package com.sinog.biz.service.census.impl;

import com.sinog.biz.config.ThreadPoolConfig;
import com.sinog.biz.mapper.havexml.DepartmentMapper;
import com.sinog.biz.mapper.havexml.SystemCodeMapper;
import com.sinog.biz.mapper.havexml.census.AllCensusMapper;
import com.sinog.biz.mapper.havexml.census.BdStatisticalReportsJyMapper;
import com.sinog.biz.mapper.havexml.census.BdStatisticalReportsMapper;
import com.sinog.biz.service.census.AllCensusService;
import com.sinog.biz.util.CodeUrlUtils;
import com.sinog.biz.util.SqlUtil;
import com.sinog.biz.util.WorkDayUtil;
import com.sinog.core.domain.AzbjRsVo;
import com.sinog.core.domain.Department;
import com.sinog.core.domain.ViewState;
import com.sinog.core.model.JobRanking;
import com.sinog.core.model.SjfxBean;
import com.sinog.core.model.UserDTO;
import com.sinog.core.util.AssemblyConversionUtils;
import com.sinog.core.util.DateUtil;
import com.sinog.core.util.JsonUtil;
import com.sinog.core.util.StrUtil;
import com.sinog.core.utilbean.Constants;
import com.sinog.core.utilbean.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * @desc - 系统中所有统计的serviceImpl
 * @author 潘志成
 * @date 2022/10/21 11:30
 */
@Slf4j
@Service
public class AllCensusServiceImpl implements AllCensusService {

    @Autowired
    private AllCensusMapper allCensusMapper;

    @Resource
    private DepartmentMapper departmentMapper;

    /**
     * SimpleDateFormat在多线程情况下会出现线程不安全，使用ThreadLocal解决
     */
    private static final ThreadLocal<DateFormat> THREAD_LOCAL_01 = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd"));

    @Autowired
    private ThreadPoolConfig threadPoolConfig;
    @Autowired
    private SystemCodeMapper systemCodeMapper;

    @Autowired
    private BdStatisticalReportsMapper bdStatisticalReportsMapper;
    @Autowired
    private BdStatisticalReportsJyMapper bdStatisticalReportsJyMapper;

    /**
     * 监狱局-核查人数
     * @param departid departid
     * @param state state 1:待核查 2:核查中 3:核查成功人员 4:核查失败人员 5:待办工作 6:已办工作
     * @return long
     */
    @Override
    public long jyjHcCount(String departid,String state) {
        return allCensusMapper.getHcCount(departid, state);
    }
    /**
     * 监狱局-衔接成功/失败人数
     * @param departid 当前登录用户机构编码
     * @param state 1:成功 3:失败
     * @return long
     */
    @Override
    public long yxjCount(String departid,String state) {
        return allCensusMapper.getXjCount(departid,state);
    }

    /**
     * 监狱局-迁移/迁出
     * @param state 1:发起迁移 2:接收迁移
     * @return long
     */
    @Override
    public long qyCount(String departid,String state) {
        return allCensusMapper.getQyCount(departid,state);
    }
    /**
     * 首页统计 - 司法所首页上方数据 - 志愿者数量
     * @param code code
     * @return Integer
     */
    @Override
    public Integer zyzCount(String code) {
        return allCensusMapper.zyzCount(code);
    }

    /**
     * 首页统计 - 司法所首页上方数据 - 安置帮教基地数量
     * @param code code
     * @return Integer
     */
    @Override
    public Integer bjjdCount(String code) {
        return allCensusMapper.bjjdCount(code);
    }

    /**
     * 首页统计 - 司法所首页上方数据 - 社会组织数量
     * @param code code
     * @return Integer
     */
    @Override
    public Integer zzCount(String code) {
        return allCensusMapper.zzCount(code);
    }

    /**
     * 首页---小卡片数量统计
     * @param departId 部门id
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> syCount(String departId) {
        return allCensusMapper.syCount(departId);
    }

    /**
     * 司法所 - 首页展示 - 帮教对象人数统计
     * @param departId 部门id
     * @return 帮教对象人数
     */
    @Override
    public Integer bjdxrs(String departId) {
        return allCensusMapper.bjdxrs(departId);
    }

    /**
     * 司法所 - 首页展示 - 重点帮教对象人数统计
     * @param departId 部门id
     * @return 重点帮教对象人数
     */
    @Override
    public Integer zdbjdxrs(String departId) {
        return allCensusMapper.zdbjdxrs(departId);
    }
    /**
     * 司法所 - 首页展示 - 基地数量
     * @param departId 部门Id
     * @return  基地数量
     */
    @Override
    public Integer azbjjd(String departId) {
        return allCensusMapper.sfsjdsl(departId);
    }

    /**
     * 司法所 - 首页展示 - 社会组织数量
     * @param departId 部门Id
     * @return  社会组织数量
     */
    @Override
    public Integer shzz(String departId) {
        return allCensusMapper.sfsshzzsl(departId);
    }

    /**
     * 司法所 - 首页展示 - 志愿者数量
     * @param departId 部门Id
     * @return  志愿者数量
     */
    @Override
    public Integer zyzrs(String departId) {
        return allCensusMapper.sfszyzsl(departId);
    }

    /**
     * 首页统计 - 点击获取全国地区数量 - 全部帮教对象
     * @param code code
     * @return List<HashMap < String,Object>>
     */
    @Override
    public List<HashMap<String,Object>> allbjDtCount(String code) {
        return allCensusMapper.allbjDtCount(code);
    }

    /**
     * 首页统计 - 点击获取全国地区数量 - 重点帮教
     * @param code code
     * @return List<HashMap < String,Object>>
     */
    @Override
    public List<HashMap<String,Object>> zdbjDtCount(String code) {
        return allCensusMapper.zdbjDtCount(code);
    }

    /**
     * 首页统计 - 点击获取全国地区数量 - 未衔接
     * @param code code
     * @return List<HashMap < String,Object>>
     */
    @Override
    public List<HashMap<String,Object>> wxjDtCount(String code) {
        return allCensusMapper.wxjDtCount(code);
    }

    /**
     * 首页统计 - 点击获取全国地区数量 - 失联
     * @param code code
     * @return List<HashMap < String,Object>>
     */
    @Override
    public List<HashMap<String,Object>> slDtCount(String code) {
        return allCensusMapper.slDtCount(code);
    }

    /**
     * 首页统计 - 安置帮教对象总数 - 当前月往前推12个月
     * @return List<String>
     */
    @Override
    public List<String> getMonth() {
        return allCensusMapper.getMonth();
    }

    /**
     * 首页统计 - 安置帮教对象总数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> a1LastYear(String departId) {
        return allCensusMapper.a1LastYear(departId);
    }

    /**
     * 首页统计 - 安置帮教对象总数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> a1Year(String departId) {
        return allCensusMapper.a1Year(departId);
    }

    /**
     * 首页统计 - 安置帮教对象总数
     * @param departId departId
     * @return List<String>
     */
    @Override
    public List<String> countSum1(String departId) {
        return allCensusMapper.countSum1(departId);
    }

    /**
     * 首页统计 - 重点帮教对象
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> a2Year(String departId) {
        return allCensusMapper.a2Year(departId);
    }

    /**
     * 首页统计 - 重点帮教对象
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> a2LastYear(String departId) {
        return allCensusMapper.a2LastYear(departId);
    }

    /**
     * 首页统计 - 重点帮教对象
     * @param departId departId
     * @return List<String>
     */
    @Override
    public List<String> countSum2(String departId) {
        return allCensusMapper.countSum2(departId);
    }

    /**
     * 首页统计 - 核查人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> a3Year(String departId) {
        return allCensusMapper.a3Year(departId);
    }

    /**
     * 首页统计 - 核查人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> a3LastYear(String departId) {
        return allCensusMapper.a3LastYear(departId);
    }

    /**
     * 首页统计 - 核查人数
     * @param departId departId
     * @return List<String>
     */
    @Override
    public List<String> countSum3(String departId) {
        return allCensusMapper.countSum3(departId);
    }

    /**
     * 首页统计 - 衔接成功人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> a4Year(String departId) {
        return allCensusMapper.a4Year(departId);
    }

    /**
     * 首页统计 - 衔接人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> a4LastYear(String departId) {
        return allCensusMapper.a4LastYear(departId);
    }

    /**
     * 首页统计 - 衔接人数
     * @param departId departId
     * @return List<String>
     */
    @Override
    public List<String> countSum4(String departId) {
        return allCensusMapper.countSum4(departId);
    }

    /**
     * 首页统计 - 安置人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> a5Year(String departId) {
        return allCensusMapper.a5Year(departId);
    }

    /**
     * 首页统计 - 安置人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> a5LastYear(String departId) {
        return allCensusMapper.a5LastYear(departId);
    }

    /**
     * 首页统计 - 安置人数
     * @param departId departId
     * @return List<String>
     */
    @Override
    public List<String> countSum5(String departId) {
        return allCensusMapper.countSum5(departId);
    }

    /**
     * 首页统计 - 帮教人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> a6Year(String departId) {
        return allCensusMapper.a6Year(departId);
    }

    /**
     * 首页统计 - 帮教人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> a6LastYear(String departId) {
        return allCensusMapper.a6LastYear(departId);
    }

    /**
     * 首页统计 - 帮教人数
     * @param departId departId
     * @return List<String>
     */
    @Override
    public List<String> countSum6(String departId) {
        return allCensusMapper.countSum6(departId);
    }

    /**
     * 首页统计 - 核查总数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> b1Year(String departId) {
        return allCensusMapper.b1Year(departId);
    }

    /**
     * 首页统计 - 去年的核查总数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> b1LastYear(String departId) {
        return allCensusMapper.b1LastYear(departId);
    }

    /**
     * 首页统计 - 核查成功人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> b2Year(String departId) {
        return allCensusMapper.b2Year(departId);
    }

    /**
     * 首页统计 - 核查成功人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> b2LastYear(String departId) {
        return allCensusMapper.b2LastYear(departId);
    }

    /**
     * 首页统计 - 核查失败人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> b3Year(String departId) {
        return allCensusMapper.b3Year(departId);
    }

    /**
     * 首页统计 - 核查失败人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> b3LastYear(String departId) {
        return allCensusMapper.b3LastYear(departId);
    }

    /**
     * 首页统计 - 衔接失败人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> b4Year(String departId) {
        return allCensusMapper.b4Year(departId);
    }

    /**
     * 首页统计 - 衔接失败人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> b4LastYear(String departId) {
        return allCensusMapper.b4LastYear(departId);
    }

    /**
     * 首页统计 - 衔接成功人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> b5Year(String departId) {
        return allCensusMapper.b5Year(departId);
    }

    /**
     * 首页统计 - 衔接成功人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> b5LastYear(String departId) {
        return allCensusMapper.b5LastYear(departId);
    }

    /**
     * 首页统计 - 未衔接人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> b6Year(String departId) {
        return allCensusMapper.b6Year(departId);
    }

    /**
     * 首页统计 - 未衔接人数
     * @param departId departId
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> b6LastYear(String departId) {
        return allCensusMapper.b6LastYear(departId);
    }

    /**
     * 首页统计 - 核查总数
     * @param departId departId
     * @return List<String>
     */
    @Override
    public List<String> countSum7(String departId) {
        return allCensusMapper.countSum7(departId);
    }

    /**
     * 首页统计 - 核查成功人数
     * @param departId departId
     * @return List<String>
     */
    @Override
    public List<String> countSum8(String departId) {
        return allCensusMapper.countSum8(departId);
    }

    /**
     * 首页统计 - 核查失败人数
     * @param departId departId
     * @return List<String>
     */
    @Override
    public List<String> countSum9(String departId) {
        return allCensusMapper.countSum9(departId);
    }

    /**
     * 首页统计 - 衔接失败人数
     * @param departId departId
     * @return List<String>
     */
    @Override
    public List<String> countSum10(String departId) {
        return allCensusMapper.countSum10(departId);
    }

    /**
     * 首页统计 - 衔接成功人数
     * @param departId departId
     * @return List<String>
     */
    @Override
    public List<String> countSum11(String departId) {
        return allCensusMapper.countSum11(departId);
    }

    /**
     * 首页统计 - 未衔接人数
     * @param departId departId
     * @return List<String>
     */
    @Override
    public List<String> countSum12(String departId) {
        return allCensusMapper.countSum12(departId);
    }

    /**
     * 描述
     * @param departId departId
     * @return List<String>
     */
    @Override
    public List<String> getDepartId(String departId) {
        return allCensusMapper.getDepartId(departId);
    }

    /**
     * 数据统计分析 - 数据分析 - 获取统计范围(返回当前用户及其子机构用户)
     * @param user user
     * @return String
     */
    @Override
    public String getTjdqfw(UserDTO user) {
        Map<String,String> map = new HashMap<>(16);
        map.put("level",user.getLevel());
        map.put("orgid",user.getOrgid());
        map.put("departid",user.getDepartid());
        List<Map<String,String>> result = departmentMapper.getLevelDepart(map);
        return JsonUtil.toText(result);
    }

    /**
     * 数据统计分析 - 数据分析 - 分析
     * @param param param
     * @param user user
     * @return Result
     */
    @Override
    public Result analysis(String param,UserDTO user) {
        //1、参数转bean，方便操作
        SjfxBean sjfxBean = JsonUtil.toBean(param,SjfxBean.class);
        //2、根据开始日期和结束日期遍历月份：2022-04-01T00:00:00.000+0800
        List<Date> monthList = DateUtil.sixMonthDate(sjfxBean.getBeginTime(),sjfxBean.getEndTime());
        //3、机构名称返回给前台
        List<String> columns = new ArrayList<>(16);
        //4、返回前端的数据
        List<Map<String,Object>> rows = new ArrayList<>(16);
        //5、根据统计项ID查询sql
        String sql = allCensusMapper.getDySql(sjfxBean.getQuota());
        //6、根据统计项ID查询统计项名称
        String codeName = allCensusMapper.getcodeNameByCode(sjfxBean.getQuota());
        //7、遍历所选地区
        List<String> dqfwids = sjfxBean.getDqfwids();
        dqfwids.forEach(departId -> {
            Department department = departmentMapper.getDepartmentById(departId);
            columns.add(department.getName());
            Map<String,Object> rowsMap = new HashMap<>(16);
            rowsMap.put("name",department.getName());
            //使用异步编排,优化数据查询速度，遍历月份
            List<CompletableFuture<Double>> collect = monthList.stream()
                                                               .map(onMonth -> CompletableFuture.supplyAsync(() -> {
                                                                   Calendar cal01 = Calendar.getInstance();
                                                                   cal01.setTime(onMonth);//这个是开始日期
                                                                   cal01.set(Calendar.DAY_OF_MONTH,cal01.getActualMaximum(Calendar.DAY_OF_MONTH));
                                                                   Date endtime = cal01.getTime();//结束时间
                                                                   Map<String,Object> paramMap = new HashMap<>(16);
                                                                   paramMap.put("departid",departId);
                                                                   paramMap.put("begintime",THREAD_LOCAL_01.get()
                                                                                                           .format(onMonth));//用来格式化日期
                                                                   paramMap.put("endtime",THREAD_LOCAL_01.get()
                                                                                                         .format(endtime));
                                                                   paramMap.put("level",departmentMapper.getDepartmentById(departId)
                                                                                                        .getLevel());
                                                                   //替换sql中的问号?并且执行该sql
                                                                   return allCensusMapper.quotaCount(SqlUtil.replace(sql,paramMap));
                                                               },threadPoolConfig.taskExecutor())).collect(Collectors.toList());
            rowsMap.put("data",collect.stream().map(CompletableFuture::join).collect(Collectors.toList()));
            rows.add(rowsMap);
        });
        //8、扇形图，获取这个月所选机构的统计总数
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        //9、返回前端的X轴数据，时间格式化，如：2022-01
        List<String> xAlist = new ArrayList<>(16);
        //10、每个月一个map
        List<Map<String,Object>> sxList = new ArrayList<>(16);
        for(Date onMonth : monthList) {
            Map<String,Object> sxMap = new HashMap<>(16);
            xAlist.add(sdf.format(onMonth));
            sxMap.put("name",sdf.format(onMonth));
            double count = 0.00;
            Calendar cal01 = Calendar.getInstance();
            //这个是开始日期
            cal01.setTime(onMonth);
            cal01.set(Calendar.DAY_OF_MONTH,cal01.getActualMaximum(Calendar.DAY_OF_MONTH));
            //结束时间
            Date endtime = cal01.getTime();
            for(int i = 0; i < sjfxBean.getDqfwids().size(); i++) {
                Map<String,Object> paramMap = new HashMap<>(16);
                paramMap.put("departid",sjfxBean.getDqfwids().get(i));
                paramMap.put("begintime",THREAD_LOCAL_01.get().format(onMonth));
                paramMap.put("endtime",THREAD_LOCAL_01.get().format(endtime));
                count += allCensusMapper.quotaCount(SqlUtil.replace(sql,paramMap));
            }
            sxMap.put("value",count);
            sxList.add(sxMap);
        }
        Map<String,Object> resultMap = new HashMap<>(16);
        resultMap.put("columns",columns);
        resultMap.put("rows",JsonUtil.toText(rows));
        resultMap.put("xAlist",xAlist);
        resultMap.put("sxList",JsonUtil.toText(sxList));
        resultMap.put("rowstest",rows);
        resultMap.put("code",sjfxBean.getQuota());
        resultMap.put("codeName",codeName);
        return Result.success(JsonUtil.toText(resultMap));
    }

    /**
     * 数据统计分析 - 数据分析 - 查询分析项(统计分析左侧树一级菜单)
     * @param type type
     * @param parentCode parentCode
     * @param user user
     * @return List<Map < String,String>>
     */
    @Override
    public List<Map<String,String>> getItemList(String type,String parentCode,UserDTO user) {
        return allCensusMapper.queryAnalysis(type,parentCode,user.getLevel());
    }

    /**
     * 数据统计分析 - 数据分析 - 左侧树展开
     * @param parentCode parentCode
     * @param user user
     * @return String
     */
    @Override
    public String getCategoryTree(String parentCode,UserDTO user) {
        List<SjfxBean> list = allCensusMapper.getCategoryTree(parentCode,user.getLevel());
        return JsonUtil.toText(list);
    }
    ////////////////////////////////5、统计分析报表 6、数据指标统计////////////////////////////////

    /**
     * 数据统计分析 - 统计分析报表 - 统计
     * @param departid departid 监狱局所管辖的监狱id
     * @param level level 单位机构
     * @param startDate startDate 开始日期
     * @param endDate endDate 结束日期
     * @return String
     */
    @Override
    public String getStatisticalReports(String departid,String level,String startDate,String endDate) {
        //处理第一次点击默认日期未当年1月1日-今天
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar date = Calendar.getInstance();
        if(StringUtils.equals(startDate,Constants.NumberStr.NUM_STR_FU_ONE)) {
            startDate = String.valueOf(date.get(Calendar.YEAR));
            startDate += "-01-01";
        }
        if(StringUtils.equals(endDate,Constants.NumberStr.NUM_STR_FU_ONE)) {
            endDate = sdf.format(new Date());
        }
        //处理endDate，给endDate加一天,因为sql用的between and，计算不了今天的内容
        try {
            date.setTime(sdf.parse(endDate));
            date.add(Calendar.DATE,1);
            endDate = sdf.format(date.getTime());
        } catch(ParseException e) {
            throw new RuntimeException(e);
        }
        List<Map<String,String>> data = new ArrayList<>(16);
        List<Map<String,String>> data1 = new ArrayList<>(16);
        //06-司法厅、07-司法局、08-司法局、03-司法所
        if(StringUtils.equals(Constants.OrgLevel.LEVEL_SFS,level) || StringUtils.equals(Constants.OrgLevel.LEVEL_SFT,level) || StringUtils.equals(Constants.OrgLevel.LEVEL_DSSFJ,level) || StringUtils.equals(Constants.OrgLevel.LEVEL_QXSFJ,level)) {
            String childLevel = "";
            if(Constants.OrgLevel.LEVEL_SFT.equals(level)) {
                childLevel = Constants.OrgLevel.LEVEL_DSSFJ;
            } else if(Constants.OrgLevel.LEVEL_DSSFJ.equals(level)) {
                childLevel = Constants.OrgLevel.LEVEL_QXSFJ;
            } else if(Constants.OrgLevel.LEVEL_QXSFJ.equals(level)) {
                childLevel = Constants.OrgLevel.LEVEL_SFS;
            }
            //直辖市特殊处理
            if(StrUtil.containsEquals(departid,Constants.XzqhCode.BEIJING,Constants.XzqhCode.TIANJIN,Constants.XzqhCode.SHANGHAI,Constants.XzqhCode.CHONGQING)) {
                childLevel = Constants.OrgLevel.LEVEL_QXSFJ;
                //查询直辖市-市辖区的departid
                List<Map<String,String>> maps = systemCodeMapper.selectChilds(departid);
                departid = maps.get(0).get("departId");
            }
            List<Map<String,String>> maps = systemCodeMapper.selectChilds(departid);
            Class<BdStatisticalReportsMapper> bdStatisticalReportsMapperClass = BdStatisticalReportsMapper.class;
            //获取类中所有方法
            Method[] methods = bdStatisticalReportsMapperClass.getMethods();
            List<Method> methodList = new ArrayList<>();
            for(Method method : methods) {
                String name = method.getName();
                if(name.startsWith("bb")) {
                    methodList.add(method);
                }
            }
            for(Map<String,String> map1 : maps) {
                String finalChildLevel = childLevel;
                String finalStartDate = startDate;
                String finalEndDate = endDate;
                String id = "";
                String name = "";
                Map<String,Integer> map = new HashMap<>(16);
                Map<String,String> map222 = new HashMap<>(16);
                List<Map<String,Integer>> statisticalReports = new CopyOnWriteArrayList<>();
                CountDownLatch countDownLatch = new CountDownLatch(methodList.size());
                for(int i = 0; i < methodList.size(); i++) {
                    int finalI = i;
                    name = map1.get("departName");
                    String departId = map1.get("departId");
                    long start = System.currentTimeMillis();
                    threadPoolConfig.taskExecutor().submit(() -> {
                        try {
                            statisticalReports.add((Map<String,Integer>)(methodList.get(finalI).invoke(bdStatisticalReportsMapper,departId,finalChildLevel,finalStartDate,finalEndDate)));
                        } catch(IllegalAccessException | InvocationTargetException e) {
                            throw new RuntimeException(e);
                        } finally {
                            long timeConsuming = System.currentTimeMillis() - start;
                            countDownLatch.countDown();
                            log.info("bdStatisticalReports>>>>>>>>>>>>>>> 耗时:{}秒",timeConsuming / 1000);
                            log.info(">>>>>第{}次，方法：{}，>>>>>countdown剩余{}>>>>>>>>>>>>>>>>>>>>>",finalI + 1,methodList.get(finalI)
                                                                                                                    .getName(),countDownLatch.getCount() + "");
                        }
                    });
                }
                try {
                    countDownLatch.await();
                } catch(InterruptedException e) {
                    e.printStackTrace();
                }
                for(Map<String,Integer> m1 : statisticalReports) {
                    map.putAll(m1);
                }
                //重点帮教对象接送率计算
                Double zdjczfjh = Double.parseDouble(map.get("zdjczfjh")+"");
                Double zdjssh = Double.parseDouble(map.get("zdjssh")+"");
                Double zdsfsjjczzjh = Double.parseDouble(map.get("zdsfsjjczzjh")+"");
                double zdbj = Double.parseDouble(map.get("zdbj")+"");
                double total = zdjczfjh+zdjssh+zdsfsjjczzjh;
                //重点帮教接送率 = （基层政府接回+监所送回+司法所及基层组织接回）/重点帮教人数
                if (Constants.Census.ZERO_ZERO.equals(zdbj+"") || Constants.Census.ZERO_ZERO.equals(total+"")) {
                    map222.put("zdbjjsl",Constants.NumberStr.NUM_STR_ZERO);
                }else {
                    String zdbjjsl = String.format("%.2f",(total * 100 / zdbj));
                    if (Constants.Census.ONE_HUNDRED.equals(zdbjjsl)) {
                        zdbjjsl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
                    } else if (Constants.Census.ZERO_ZERO_ZERO.equals(zdbjjsl)) {
                        zdbjjsl = Constants.NumberStr.NUM_STR_ZERO;
                    }
                    map222.put("zdbjjsl", zdbjjsl);
                }
                map222.put("childs",name);
                map222.put("childsId",id);
                for(Map.Entry<String,Integer> entry1 : map.entrySet()) {
                    String mapKey1 = entry1.getKey();
                    Integer mapValue1 = ((Number)entry1.getValue()).intValue();
                    map222.put(mapKey1,mapValue1 + "");
                }
                data.add(map222);
            }
            data1 = data.stream().sorted(Comparator.comparing(AllCensusServiceImpl::comparingByName))
                        .collect(Collectors.toList());
            Map<String,Integer> map = new HashMap<>(16);
            getListInfo(map,data1,level);
            Map<String,String> map222 = new HashMap<>(16);
            //合计：重点帮教接送率 = （基层政府接回+监所送回+司法所及基层组织接回）/重点帮教人数
            Integer zdjczfjh = map.get("zdjczfjh");
            Integer zdjssh = map.get("zdjssh");
            Integer zdsfsjjczzjh = map.get("zdsfsjjczzjh");
            double total = Double.parseDouble((zdjczfjh+zdjssh+zdsfsjjczzjh)+"");
            double zdbj = Double.parseDouble(map.get("zdbj")+"");
            if (Constants.Census.ZERO_ZERO.equals(zdbj+"") || Constants.Census.ZERO_ZERO.equals(total+"")) {
                map.put("zdbjjsl",0);
            } else {
                String zdbjjsl = String.format("%.2f",(total * 100 / zdbj));
                if (Constants.Census.ONE_HUNDRED.equals(zdbjjsl)) {
                    zdbjjsl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
                } else if (Constants.Census.ZERO_ZERO_ZERO.equals(zdbjjsl)) {
                    zdbjjsl = Constants.NumberStr.NUM_STR_ZERO;
                }
                map222.put("zdbjjsl",zdbjjsl);
            }

            for(Map.Entry<String,Integer> entry1 : map.entrySet()) {
                String mapKey1 = entry1.getKey();
                Integer mapValue1 = entry1.getValue();
                map222.put(mapKey1,mapValue1 + "");
            }
            map222.put("childs","合计");
            data1.add(map222);
        } else {
            //监狱管理局-统计分析报表
            Map<String,Integer> map = new HashMap<>(16);
            Map<String,String> map222 = new HashMap<>(16);
            List<Integer> statisticalReports = allCensusMapper.getStatisticalJyReports(departid,level,startDate,endDate,null);
            getListJyInfo(map,statisticalReports);
            for(Map.Entry<String,Integer> entry1 : map.entrySet()) {
                String mapKey1 = entry1.getKey();
                Integer mapValue1 = entry1.getValue();
                map222.put(mapKey1,mapValue1 + "");
            }
            data1.add(map222);
        }
        return JsonUtil.toText1(data1);
    }

    /**
     * 数据统计分析 - 数据指标统计 - 统计
     * @param departid departid
     * @param level level
     * @param startDate 开始日期
     * @param endDate 结束日期
     * @return String
     */
    @Override
    public String getBdStatisticalReports(String departid,String level,String startDate,String endDate) {
        String param = "";
        String paramOwner = "";
        String oldDepartid = departid;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar date = Calendar.getInstance();
        if(StringUtils.equals(startDate,Constants.NumberStr.NUM_STR_FU_ONE)) {
            startDate = String.valueOf(date.get(Calendar.YEAR));
            startDate += "-01-01";
        }
        if(StringUtils.equals(endDate,Constants.NumberStr.NUM_STR_FU_ONE)) {
            endDate = sdf.format(new Date());
        }
        //处理endDate，给endDate加一天,因为sql用的between and，计算不了今天的内容
        try {
            date.setTime(sdf.parse(endDate));
            date.add(Calendar.DATE,1);
            endDate = sdf.format(date.getTime());
        } catch(ParseException e) {
            throw new RuntimeException(e);
        }
        // 直辖市特殊处理
        if(StrUtil.containsEquals(departid,Constants.XzqhCode.BEIJING,Constants.XzqhCode.TIANJIN,Constants.XzqhCode.SHANGHAI,Constants.XzqhCode.CHONGQING)) {
            departid = departid.substring(0,3).concat(Constants.NumberStr.NUM_STR_ONE_HUNDRED);
            param = "nativecou";
            paramOwner = "nativecity";
        } else if(Constants.OrgLevel.LEVEL_SFT.equals(level)) {
            param = "nativecity";
            paramOwner = "nativepro";
        } else if(Constants.OrgLevel.LEVEL_DSSFJ.equals(level)) {
            param = "nativecou";
            paramOwner = "nativecity";
        } else if(Constants.OrgLevel.LEVEL_QXSFJ.equals(level)) {
            param = "nativevill";
            paramOwner = "nativecou";
        } else if(Constants.OrgLevel.LEVEL_JYJ.equals(level)) {
            param = "adduserid";
            paramOwner = "nativepro";
            departid = departid + "00";
        } else if(Constants.OrgLevel.LEVEL_JY.equals(level)) {
            param = "adduserid";
            paramOwner = "adduserid";
        }else if(Constants.OrgLevel.LEVEL_SFS.equals(level)) {
            param = "nativevill";
            paramOwner = "nativevill";
        }
        //根据当前部门ID、截止日期、行政区划层级 查询每个省份各指标数据
        List<Map<String,Object>> bdStatisticalReports = new ArrayList<>();
        if(StringUtils.equals(Constants.OrgLevel.LEVEL_JY,level) || Constants.OrgLevel.LEVEL_JYJ.equals(level)) {
            //监狱局
            //获取类对象
            Class<BdStatisticalReportsJyMapper> bdStatisticalReportsJyMapperClass = BdStatisticalReportsJyMapper.class;
            //获取类中所有方法
            Method[] methods = bdStatisticalReportsJyMapperClass.getMethods();
            //为了防止这个类中以后添加其他方法，在这里做一个判断，只获取包含all的方法
            List<Method> methodList = new ArrayList<>();
            for(Method method : methods) {
                String name = method.getName();
                if(name.contains("all")) {
                    methodList.add(method);
                }
            }
            Map<String,Object> map = new HashMap<>(16);
            CountDownLatch countDownLatch = new CountDownLatch(methodList.size());
            for(int i = 0; i < methodList.size(); i++) {
                int finalI = i;
                String departid1 = departid;
                String param1 = param;
                String paramOwner1 = paramOwner;
                String startDate1 = startDate;
                String endDate1 = endDate;
                threadPoolConfig.taskExecutor().submit(() -> {
                    List<Map<String,Object>> invoke;
                    long start = System.currentTimeMillis();
                    try {
                        invoke = (List<Map<String,Object>>)methodList.get(finalI)
                                                                     .invoke(bdStatisticalReportsJyMapper,departid1,param1,paramOwner1,startDate1,endDate1);
                        map.put(methodList.get(finalI).getName(),invoke);
                    } catch(IllegalAccessException | InvocationTargetException e) {
                        e.printStackTrace();
                    } finally {
                        long timeConsuming = System.currentTimeMillis() - start;
                        log.info("bdStatisticalReports>>>>>>>>>>>>>>> 耗时:{}秒",timeConsuming / 1000);
                        countDownLatch.countDown();
                    }
                });
            }
            try {
                countDownLatch.await();
            } catch(InterruptedException e) {
                throw new RuntimeException(e);
            }
            Map<String,Object> result = new TreeMap<>(new MapKeyComparator());
            result.putAll(map);
            for(Map.Entry<String,Object> next : result.entrySet()) {
                List<Map<String,Object>> list = (List<Map<String,Object>>)next.getValue();
                bdStatisticalReports.addAll(list);
            }
        } else {
            //获取类对象
            Class<BdStatisticalReportsMapper> bdStatisticalReportsMapperClass = BdStatisticalReportsMapper.class;
            //获取类中所有方法
            Method[] methods = bdStatisticalReportsMapperClass.getMethods();
            //为了防止这个类中以后添加其他方法，在这里做一个判断，只获取包含all的方法
            List<Method> methodList = new ArrayList<>();
            for(Method method : methods) {
                String name = method.getName();
                if(name.startsWith("all")) {
                    methodList.add(method);
                }
            }
            Map<String,Object> map = new HashMap<>(16);
            CountDownLatch countDownLatch = new CountDownLatch(methodList.size());
            for(int i = 0; i < methodList.size(); i++) {
                int finalI = i;
                String departid1 = departid;
                String param1 = param;
                String paramOwner1 = paramOwner;
                String startDate1 = startDate;
                String endDate1 = endDate;
                threadPoolConfig.taskExecutor().submit(() -> {
                    List<Map<String,Object>> invoke;
                    long start = System.currentTimeMillis();
                    try {
                        invoke = (List<Map<String,Object>>)methodList.get(finalI)
                                                                     .invoke(bdStatisticalReportsMapper,departid1,param1,paramOwner1,startDate1,endDate1);
                        map.put(methodList.get(finalI).getName(),invoke);
                    } catch(IllegalAccessException | InvocationTargetException e) {
                        e.printStackTrace();
                    } finally {
                        long timeConsuming = System.currentTimeMillis() - start;
                        log.info("bdStatisticalReports>>>>>>>>>>>>>>> 耗时:{}秒",timeConsuming / 1000);
                        countDownLatch.countDown();
                    }
                });
            }
            try {
                countDownLatch.await();
            } catch(InterruptedException e) {
                throw new RuntimeException(e);
            }
            Map<String,Object> result = new TreeMap<>(new MapKeyComparator());
            result.putAll(map);
            for(Map.Entry<String,Object> next : result.entrySet()) {
                List<Map<String,Object>> list = (List<Map<String,Object>>)next.getValue();
                bdStatisticalReports.addAll(list);
            }
        }
        Map<String,Map<String,String>> mapffff = new HashMap<>(16);
        List<Map<String,String>> data1 = new ArrayList<>();
        //遍历各个单位，填充mapffff
        for(Map<String,Object> map : bdStatisticalReports) {
            String code = (String)map.get("code");
            if(!StringUtils.isEmpty(code)) {
                int i = code.indexOf("-");
                String substring = code.substring(0,i);
                if(!StringUtils.isEmpty(substring)) {
                    if(null == mapffff.get(substring) || mapffff.get(substring).size() <= 0) {
                        if(Constants.OrgLevel.LEVEL_JYJ.equals(level) && substring.length() == 4) {
                            //监狱管理局
                            mapffff.put(substring,new HashMap<>(16));
                        } else {
                            //司法
                            mapffff.put(substring,new HashMap<>(16));
                        }
                    }
                }
            }
        }
        //遍历各个单位，为每个指标设置keyName
        //总计
        int hczrsSjCount= 0;
        int hczrsJyCount= 0;
        int hczrsKssCount= 0;
        int hczrsCount= 0;
        int lrrsJyCount= 0;
        int lrrsKssCount= 0;
        int lrrsSjCount= 0;
        int sfsblCount= 0;
        int lrrsCount= 0;
        int hccgsCount= 0;
        int xjzsJyCount= 0;
        int xjzsKssCount= 0;
        int xjzsSjCount= 0;
        int xjzsCount= 0;
//        int xjcgsCount= 0;
        int azzsCount= 0;
        int bjzsCount= 0;
        int jzzsCount= 0;
        int wchczrsJyCount= 0;
        int wchczrsKssCount= 0;
        int wchczrsSjCount= 0;
        int wchczrsCount= 0;
        int zdbjCount= 0;
        int xmsfCount= 0;
        int zdxmsfCount= 0;
        for(Map<String,Object> map : bdStatisticalReports) {
            String code = (String)map.get("code");
            String name = (String)map.get("name");
            Long count = (Long)map.get("count");
            if(!StringUtils.isEmpty(code)) {
                int i = code.indexOf("-");
                String substring = code.substring(0,i);
                if(!StringUtils.isEmpty(substring)) {
                    if(code.contains("-0013")) {
                        //发起核查总人数 - 社矫
                        mapffff.get(substring).put("hczrs_sj",count + "");
                        hczrsSjCount += count.intValue();
                    } else if(code.contains("-0011")) {
                        //发起核查总人数 - 监狱
                        mapffff.get(substring).put("hczrs_jy",count + "");
                        hczrsJyCount += count.intValue();
                    } else if(code.contains("-0012")) {
                        //发起核查总人数 - 看守所
                        mapffff.get(substring).put("hczrs_kss",count + "");
                        hczrsKssCount += count.intValue();
                    } else if(code.contains("-001")) {
                        //发起核查总人数
                        mapffff.get(substring).put("hczrs",count + "");
                        hczrsCount += count.intValue();
                    } else if(code.contains("-0021")) {
                        //录入总数 - 监狱
                        mapffff.get(substring).put("lrrs_jy",count + "");
                        lrrsJyCount += count.intValue();
                    } else if(code.contains("-0022")) {
                        //录入总数 - 看守所
                        mapffff.get(substring).put("lrrs_kss",count + "");
                        lrrsKssCount += count.intValue();
                    } else if(code.contains("-0023")) {
                        //录入总数 - 社矫
                        mapffff.get(substring).put("lrrs_sj",count + "");
                        lrrsSjCount += count.intValue();
                    } else if(code.contains("-0024")) {
                        //司法所补录
                        mapffff.get(substring).put("sfsbl",count + "");
                        sfsblCount += count.intValue();
                    } else if(code.contains("-002")) {
                        //录入总数
                        mapffff.get(substring).put("lrrs",count + "");
                        lrrsCount += count.intValue();
                    } else if(code.contains("-003")) {
                        //核查成功数
                        mapffff.get(substring).put("hccgs",count + "");
                        hccgsCount += count.intValue();
                    } else if(code.contains("-0041")) {
                        //衔接总人数 - 监狱
                        mapffff.get(substring).put("xjzs_jy",count + "");
                        xjzsJyCount += count.intValue();
                    }  else if(code.contains("-0042")) {
                        //衔接总人数 - 看守所
                        mapffff.get(substring).put("xjzs_kss",count + "");
                        xjzsKssCount += count.intValue();
                    } else if(code.contains("-0043")) {
                        //衔接总人数 - 社矫
                        mapffff.get(substring).put("xjzs_sj",count + "");
                        xjzsSjCount += count.intValue();
                    } else if(code.contains("-004")) {
                        //衔接总人数
                        mapffff.get(substring).put("xjzs",count + "");
                        xjzsCount += count.intValue();
                    }  else if(code.contains("-0051")) {
                        //重点帮教
                        mapffff.get(substring).put("zdbj",count + "");
                        zdbjCount += count.intValue();
                    }  else if(code.contains("-006")) {
                        //安置总数
                        mapffff.get(substring).put("azzs",count + "");
                        azzsCount += count.intValue();
                    } else if(code.contains("-007")) {
                        //帮教总数
                        mapffff.get(substring).put("bjzs",count + "");
                        bjzsCount += count.intValue();
                    } else if(code.contains("-008")) {
                        //救助总数
                        mapffff.get(substring).put("jzzs",count + "");
                        jzzsCount += count.intValue();
                    } else if(code.contains("-0091")) {
                        //司法所完成核查总人数 - 监狱
                        mapffff.get(substring).put("wchczrs_jy",count + "");
                        wchczrsJyCount += count.intValue();
                    } else if(code.contains("-0092")) {
                        //司法所完成核查总人数 - 看守所
                        mapffff.get(substring).put("wchczrs_kss",count + "");
                        wchczrsKssCount += count.intValue();
                    } else if(code.contains("-0093")) {
                        //司法所完成核查总人数 - 社矫
                        mapffff.get(substring).put("wchczrs_sj",count + "");
                        wchczrsSjCount += count.intValue();
                    } else if(code.contains("-009")) {
                        //司法所完成核查总人数
                        mapffff.get(substring).put("wchczrs",count + "");
                        wchczrsCount += count.intValue();
                    } else if(code.contains("-100")) {
                        //刑满释放人员
                        mapffff.get(substring).put("xmsf",count + "");
                        xmsfCount+= count.intValue();
                    } else if(code.contains("-101")) {
                        //重点帮教对象刑满释放总数
                        mapffff.get(substring).put("zdxmsf",count + "");
                        zdxmsfCount += count.intValue();
                    }
                    mapffff.get(substring).put("childs",name);
                }
            }
        }
        // 根据部门ID查询全部行政区划，为mapffff设置不存在的行政区划
        List<Map<String,String>> systemCode;
        if(Constants.OrgLevel.LEVEL_JYJ.equals(level)) {
            systemCode = departmentMapper.getDepartments(oldDepartid);
        } else {
            systemCode = systemCodeMapper.getSearchCodeNativeResoult(Constants.CodeType.CODE_ZHRMGHG_XZQH_DM,departid);
        }
        for(Map<String,String> map : systemCode) {
            String code = map.get("id");
            String codeName = map.get("text");
            if(mapffff.containsKey(code)) {
                continue;
            }
            HashMap<String,String> dataMap = new HashMap<>(16);
            dataMap.put("childs",codeName);
            mapffff.put(code,dataMap);
        }
        //遍历mapffff，为不存在的指标设置数据为0，并计算各种比率指标
        for(Map.Entry<String,Map<String,String>> entry1 : mapffff.entrySet()) {
            Map<String,String> value = entry1.getValue();
            value.put("childsId",entry1.getKey());
            //发起核查总人数
            value.putIfAbsent("hczrs",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("hczrs_jy",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("hczrs_kss",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("hczrs_sj",Constants.NumberStr.NUM_STR_ZERO);
            //录入总数
            value.putIfAbsent("lrrs",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("lrrs_jy",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("lrrs_kss",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("lrrs_sj",Constants.NumberStr.NUM_STR_ZERO);
            //核查成功数
            value.putIfAbsent("hccgs",Constants.NumberStr.NUM_STR_ZERO);
            //衔接总人数
            value.putIfAbsent("xjzs",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("xjzs_jy",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("wcxjzs_jy",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("xjzs_kss",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("xjzs_sj",Constants.NumberStr.NUM_STR_ZERO);
            //衔接成功总人数
            //value.putIfAbsent("xjcgs",Constants.NumberStr.NUM_STR_ZERO);
            //安置总数
            value.putIfAbsent("azzs",Constants.NumberStr.NUM_STR_ZERO);
            //帮教总数
            value.putIfAbsent("bjzs",Constants.NumberStr.NUM_STR_ZERO);
            //救助总数
            value.putIfAbsent("jzzs",Constants.NumberStr.NUM_STR_ZERO);
            //司法所完成核查总人数
            value.putIfAbsent("wchczrs",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("wchczrs_jy",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("wchczrs_kss",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("wchczrs_sj",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("xmsf",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("zdxmsf",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("sfsbl",Constants.NumberStr.NUM_STR_ZERO);
            value.putIfAbsent("zdbj",Constants.NumberStr.NUM_STR_ZERO);
            //发起核查总人数
            double hczrs = Double.parseDouble(value.get("hczrs"));
            //完成核查总人数
            double wchczrs = Double.parseDouble(value.get("wchczrs"));
            //核查成功数
            double hccgs = Double.parseDouble(value.get("hccgs"));
            //衔接总人数
            double xjzs = Double.parseDouble(value.get("xjzs"));
            //重点帮教人数
            double zdbj = Double.parseDouble(value.get("zdbj"));
            //刑满释放
            double xmsf = Double.parseDouble(value.get("xmsf"));
            //重点刑满释放
            double zdxmsf = Double.parseDouble(value.get("zdxmsf"));
            //衔接成功数
            //double xjcgs = Double.parseDouble(value.get("xjcgs"));
            //安置总数
            double azzs = Double.parseDouble(value.get("azzs"));
            //帮教总数
            double bjzs = Double.parseDouble(value.get("bjzs"));
            //录入总人数
            double lrrs = Double.parseDouble(value.get("lrrs"));
            //司法所补录
            double sfsbl = Double.parseDouble(value.get("sfsbl"));
            //完成核查率 = 完成核查总人数÷发起核查总人数
            if (Constants.Census.ZERO_ZERO.equals(hczrs+"") || Constants.Census.ZERO_ZERO.equals(wchczrs+"")) {
                value.put("wchcl",Constants.NumberStr.NUM_STR_ZERO);
            } else {
                String wchcl = String.format("%.2f",(wchczrs * 100 / hczrs));
                if (Constants.Census.ONE_HUNDRED.equals(wchcl)) {
                    wchcl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
                } else if (Constants.Census.ZERO_ZERO_ZERO.equals(wchcl)) {
                    wchcl = Constants.NumberStr.NUM_STR_ZERO;
                }
                value.put("wchcl",wchcl);
            }
            //核查成功率 = 核查成功数÷发起核查总人数
            if (Constants.Census.ZERO_ZERO.equals(hczrs+"") || Constants.Census.ZERO_ZERO.equals(hccgs+"")) {
                value.put("hccgl",Constants.NumberStr.NUM_STR_ZERO);
            } else {
                String hccgl = String.format("%.2f",(hccgs * 100 / hczrs));
                if (Constants.Census.ONE_HUNDRED.equals(hccgl)) {
                    hccgl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
                } else if (Constants.Census.ZERO_ZERO_ZERO.equals(hccgl)) {
                    hccgl = Constants.NumberStr.NUM_STR_ZERO;
                }
                value.put("hccgl",hccgl);
            }
            //衔接率 = 衔接总人数÷刑满释放总人数
            if (Constants.Census.ZERO_ZERO.equals(xmsf+"") || Constants.Census.ZERO_ZERO.equals(xjzs+"")) {
                value.put("xjl",Constants.NumberStr.NUM_STR_ZERO);
            } else {
                String xjl = String.format("%.2f",(xjzs * 100 / xmsf));
                if (Constants.Census.ONE_HUNDRED.equals(xjl)) {
                    xjl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
                } else if (Constants.Census.ZERO_ZERO_ZERO.equals(xjl)) {
                    xjl = Constants.NumberStr.NUM_STR_ZERO;
                }
                value.put("xjl",xjl);
            }
            //衔接成功率 = 衔接成功总人数÷衔接总人数
//            if (Constants.Census.ZERO_ZERO.equals(xjzs+"") || Constants.Census.ZERO_ZERO.equals(xjcgs+"")) {
//                value.put("xjcgl",Constants.NumberStr.NUM_STR_ZERO);
//            } else {
//                String xjcgl = String.format("%.2f",(xjcgs * 100 / xjzs));
//                if (Constants.Census.ONE_HUNDRED.equals(xjcgl)) {
//                    xjcgl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
//                } else if (Constants.Census.ZERO_ZERO_ZERO.equals(xjcgl)) {
//                    xjcgl = Constants.NumberStr.NUM_STR_ZERO;
//                }
//                value.put("xjcgl",xjcgl);
//            }
            //重点帮教衔接率 = 重点帮教对象衔接人数÷重点帮教对象刑满释放总数
            if (Constants.Census.ZERO_ZERO.equals(zdxmsf+"") || Constants.Census.ZERO_ZERO.equals(zdbj+"")) {
                value.put("zdbjl",Constants.NumberStr.NUM_STR_ZERO);
            } else {
                String zdbjl = String.format("%.2f",(zdbj * 100 / zdxmsf));
                if (Constants.Census.ONE_HUNDRED.equals(zdbjl)) {
                    zdbjl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
                } else if (Constants.Census.ZERO_ZERO_ZERO.equals(zdbjl)) {
                    zdbjl = Constants.NumberStr.NUM_STR_ZERO;
                }
                value.put("zdbjl",zdbjl);
            }
            //安置率
            if (Constants.Census.ZERO_ZERO.equals(xjzs+"") || Constants.Census.ZERO_ZERO.equals(azzs+"")) {
                value.put("azl",Constants.NumberStr.NUM_STR_ZERO);
            } else {
                String azl = String.format("%.2f",(azzs * 100 / xjzs));
                if (Constants.Census.ONE_HUNDRED.equals(azl)) {
                    azl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
                } else if (Constants.Census.ZERO_ZERO_ZERO.equals(azl)) {
                    azl = Constants.NumberStr.NUM_STR_ZERO;
                }
                value.put("azl",azl);
            }
            //帮教率
            if (Constants.Census.ZERO_ZERO.equals(xjzs+"") || Constants.Census.ZERO_ZERO.equals(bjzs+"")) {
                value.put("bjl",Constants.NumberStr.NUM_STR_ZERO);
            } else {
                String bjl = String.format("%.2f",(bjzs * 100 / xjzs));
                if (Constants.Census.ONE_HUNDRED.equals(bjl)) {
                    bjl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
                } else if (Constants.Census.ZERO_ZERO_ZERO.equals(bjl)) {
                    bjl = Constants.NumberStr.NUM_STR_ZERO;
                }
                value.put("bjl",bjl);
            }
            //发起核查率 = 发起核查总人数÷（录入总人数-司法所补录）
            if ( lrrs <= sfsbl || Constants.Census.ZERO_ZERO.equals(hczrs+"")) {
                value.put("fqhcl",Constants.NumberStr.NUM_STR_ZERO);
            } else {
                String fqhcl = String.format("%.2f",(hczrs * 100 / (lrrs-sfsbl)));
                if (Constants.Census.ONE_HUNDRED.equals(fqhcl)) {
                    fqhcl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
                } else if (Constants.Census.ZERO_ZERO_ZERO.equals(fqhcl)) {
                    fqhcl = Constants.NumberStr.NUM_STR_ZERO;
                }
                value.put("fqhcl",fqhcl);
            }
            data1.add(value);
        }
        data1 = data1.stream().sorted(Comparator.comparing(AllCensusServiceImpl::comparingByName)).collect(Collectors.toList());
        //处理总计
        Map<String,String> total = new HashMap<>(64);
        //发起核查总人数
        total.put("childs","合计");
        total.put("hczrs",hczrsCount+"");
        total.put("hczrs_jy",hczrsJyCount+"");
        total.put("hczrs_kss",hczrsKssCount+"");
        total.put("hczrs_sj",hczrsSjCount+"");
        //录入总数
        total.put("lrrs",lrrsCount+"");
        total.put("lrrs_jy",lrrsJyCount+"");
        total.put("lrrs_kss",lrrsKssCount+"");
        total.put("lrrs_sj",lrrsSjCount+"");
        //核查成功数
        total.put("hccgs",hccgsCount+"");
        //衔接总人数
        total.put("xjzs",xjzsCount+"");
        total.put("xjzs_jy",xjzsJyCount+"");
        total.put("wcxjzs_jy",xjzsJyCount+"");
        total.put("xjzs_kss",xjzsKssCount+"");
        total.put("xjzs_sj",xjzsSjCount+"");
        //衔接成功总人数
        //total.put("xjcgs",xjcgsCount+"");
        //安置总数
        total.put("azzs",azzsCount+"");
        //帮教总数
        total.put("bjzs",bjzsCount+"");
        //救助总数
        total.put("jzzs",jzzsCount+"");
        //司法所完成核查总人数
        total.put("wchczrs",wchczrsCount+"");
        total.put("wchczrs_jy",wchczrsJyCount+"");
        total.put("wchczrs_kss",wchczrsKssCount+"");
        total.put("wchczrs_sj",wchczrsSjCount+"");
        total.put("xmsf",xmsfCount+"");
        total.put("zdxmsf",zdxmsfCount+"");
        total.put("sfsbl",sfsblCount+"");
        total.put("zdbj",zdbjCount+"");
        //完成核查率 = 完成核查总人数÷发起核查总人数
        if (Constants.NumberStr.NUM_STR_ZERO.equals(hczrsCount+"") || Constants.NumberStr.NUM_STR_ZERO.equals(wchczrsCount+"")) {
            total.put("wchcl",Constants.NumberStr.NUM_STR_ZERO);
        } else {
            double wchczrs = Double.parseDouble(wchczrsCount + ".0");
            double hczrs = Double.parseDouble(hczrsCount + ".0");
            String wchcl = String.format("%.2f",(wchczrs * 100 / hczrs));
            if (Constants.Census.ONE_HUNDRED.equals(wchcl)) {
                wchcl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
            } else if (Constants.Census.ZERO_ZERO_ZERO.equals(wchcl)) {
                wchcl = Constants.NumberStr.NUM_STR_ZERO;
            }
            total.put("wchcl",wchcl);
        }
        //核查成功率 = 核查成功数÷发起核查总人数
        if (Constants.NumberStr.NUM_STR_ZERO.equals(hczrsCount+"") || Constants.NumberStr.NUM_STR_ZERO.equals(hccgsCount+"")) {
            total.put("hccgl",Constants.NumberStr.NUM_STR_ZERO);
        } else {
            double hccgs = Double.parseDouble(hccgsCount + ".0");
            double hczrs = Double.parseDouble(hczrsCount + ".0");
            String hccgl = String.format("%.2f",(hccgs * 100 / hczrs));
            if (Constants.Census.ONE_HUNDRED.equals(hccgl)) {
                hccgl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
            } else if (Constants.Census.ZERO_ZERO_ZERO.equals(hccgl)) {
                hccgl = Constants.NumberStr.NUM_STR_ZERO;
            }
            total.put("hccgl",hccgl);
        }
        //衔接率 = 衔接总人数÷刑满释放总人数
        if (Constants.NumberStr.NUM_STR_ZERO.equals(xmsfCount+"") || Constants.NumberStr.NUM_STR_ZERO.equals(xjzsCount+"")) {
            total.put("xjl",Constants.NumberStr.NUM_STR_ZERO);
        } else {
            double xjzs = Double.parseDouble(xjzsCount + ".0");
            double xmsf = Double.parseDouble(xmsfCount + ".0");
            String xjl = String.format("%.2f",(xjzs * 100 / xmsf));
            if (Constants.Census.ONE_HUNDRED.equals(xjl)) {
                xjl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
            } else if (Constants.Census.ZERO_ZERO_ZERO.equals(xjl)) {
                xjl = Constants.NumberStr.NUM_STR_ZERO;
            }
            total.put("xjl",xjl);
        }
        //衔接成功率 = 衔接成功总人数÷衔接总人数
//        if (Constants.NumberStr.NUM_STR_ZERO.equals(xjzsCount+"") || Constants.NumberStr.NUM_STR_ZERO.equals(xjcgsCount+"")) {
//            total.put("xjcgl",Constants.NumberStr.NUM_STR_ZERO);
//        } else {
//            double xjcgs = Double.parseDouble(xjcgsCount + ".0");
//            double xjzs = Double.parseDouble(xjzsCount + ".0");
//            String xjcgl = String.format("%.2f",(xjcgs * 100 / xjzs));
//            if (Constants.Census.ONE_HUNDRED.equals(xjcgl)) {
//                xjcgl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
//            } else if (Constants.Census.ZERO_ZERO_ZERO.equals(xjcgl)) {
//                xjcgl = Constants.NumberStr.NUM_STR_ZERO;
//            }
//            total.put("xjcgl",xjcgl);
//        }
        //重点帮教衔接率 = 重点帮教对象衔接人数÷重点帮教对象刑满释放总数
        if (Constants.NumberStr.NUM_STR_ZERO.equals(zdxmsfCount+"") || Constants.NumberStr.NUM_STR_ZERO.equals(zdbjCount+"")) {
            total.put("zdbjl",Constants.NumberStr.NUM_STR_ZERO);
        } else {
            double zdbj = Double.parseDouble(zdbjCount + ".0");
            double zdxmsf = Double.parseDouble(zdxmsfCount + ".0");
            String zdbjl = String.format("%.2f",(zdbj * 100 / zdxmsf));
            if (Constants.Census.ONE_HUNDRED.equals(zdbjl)) {
                zdbjl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
            } else if (Constants.Census.ZERO_ZERO_ZERO.equals(zdbjl)) {
                zdbjl = Constants.NumberStr.NUM_STR_ZERO;
            }
            total.put("zdbjl",zdbjl);
        }
        //安置率
        if (Constants.NumberStr.NUM_STR_ZERO.equals(xjzsCount+"") || Constants.NumberStr.NUM_STR_ZERO.equals(azzsCount+"")) {
            total.put("azl",Constants.NumberStr.NUM_STR_ZERO);
        } else {
            double azzs = Double.parseDouble(azzsCount + ".0");
            double xjzs = Double.parseDouble(xjzsCount + ".0");
            String azl = String.format("%.2f",(azzs * 100 / xjzs));
            if (Constants.Census.ONE_HUNDRED.equals(azl)) {
                azl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
            } else if (Constants.Census.ZERO_ZERO_ZERO.equals(azl)) {
                azl = Constants.NumberStr.NUM_STR_ZERO;
            }
            total.put("azl",azl);
        }
        //帮教率
        if (Constants.NumberStr.NUM_STR_ZERO.equals(xjzsCount+"") || Constants.NumberStr.NUM_STR_ZERO.equals(bjzsCount+"")) {
            total.put("bjl",Constants.NumberStr.NUM_STR_ZERO);
        } else {
            double bjzs = Double.parseDouble(bjzsCount + ".0");
            double xjzs = Double.parseDouble(xjzsCount + ".0");
            String bjl = String.format("%.2f",(bjzs * 100 / xjzs));
            if (Constants.Census.ONE_HUNDRED.equals(bjl)) {
                bjl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
            } else if (Constants.Census.ZERO_ZERO_ZERO.equals(bjl)) {
                bjl = Constants.NumberStr.NUM_STR_ZERO;
            }
            total.put("bjl",bjl);
        }
        //发起核查率 = 发起核查总人数÷（录入总人数-司法所补录）
        if ( lrrsCount <= sfsblCount || Constants.NumberStr.NUM_STR_ZERO.equals(hczrsCount+"")) {
            total.put("fqhcl",Constants.NumberStr.NUM_STR_ZERO);
        } else {
            double hczrs = Double.parseDouble(hczrsCount + ".0");
            double lrrs = Double.parseDouble(lrrsCount + ".0");
            double sfsbl = Double.parseDouble(sfsblCount + ".0");
            String fqhcl = String.format("%.2f",(hczrs * 100 / (lrrs-sfsbl)));
            if (Constants.Census.ONE_HUNDRED.equals(fqhcl)) {
                fqhcl = Constants.NumberStr.NUM_STR_ONE_HUNDRED;
            } else if (Constants.Census.ZERO_ZERO_ZERO.equals(fqhcl)) {
                fqhcl = Constants.NumberStr.NUM_STR_ZERO;
            }
            total.put("fqhcl",fqhcl);
        }
        data1.add(total);
        return JsonUtil.toText1(data1);
    }

    /**
     * 处理统计分析报表--总计
     * @param map 返回的对象
     * @param statisticalReports 参数集合
     */
    private void getListInfo(Map<String,Integer> map,List<Map<String,String>> statisticalReports,String level) {
        int[] array = new int[69];
        int dsqyjdsCount = 0;
        int qxqyjdsCount = 0;
        int jdqyjdsCount = 0;
        int dszfjdsCount = 0;
        int qxzfjdsCount = 0;
        for(Map<String,String> m1 : statisticalReports) {
            array[0] += Integer.parseInt(null == m1.get("cjgs") ?"0":m1.get("cjgs"));
            array[1] += Integer.parseInt(null == m1.get("cjgrs") ?"0":m1.get("cjgrs"));
            array[2] += Integer.parseInt(null == m1.get("ccjgs") ?"0":m1.get("ccjgs"));
            array[3] += Integer.parseInt(null == m1.get("ccjgrs") ?"0":m1.get("ccjgrs"));
            array[4] += Integer.parseInt(null == m1.get("cccjgs") ?"0":m1.get("cccjgs"));
            array[5] += Integer.parseInt(null == m1.get("cccjgrs") ?"0":m1.get("cccjgrs"));
            array[6] += Integer.parseInt(null == m1.get("sgrs") ?"0":m1.get("sgrs"));
            array[7] += Integer.parseInt(null == m1.get("zyzrs") ?"0":m1.get("zyzrs"));
            array[8] += Integer.parseInt(null == m1.get("xjzs") ?"0":m1.get("xjzs"));
            array[9] += Integer.parseInt(null == m1.get("jysf")?"0":m1.get("jysf"));
            array[10] += Integer.parseInt(null == m1.get("ksssf")?"0":m1.get("ksssf"));
            array[11] += Integer.parseInt(null == m1.get("sqjzzr") ?"0":m1.get("sqjzzr"));
            array[12] += Integer.parseInt(null == m1.get("man") ?"0":m1.get("man"));
            array[13] += Integer.parseInt(null == m1.get("woman") ?"0":m1.get("woman"));
            array[14] += Integer.parseInt(null == m1.get("ncj") ?"0":m1.get("ncj"));
            array[15] += Integer.parseInt(null == m1.get("sanwu") ?"0":m1.get("sanwu"));
            array[16] += Integer.parseInt(null == m1.get("zdbj")?"0": m1.get("zdbj"));
            array[17] += Integer.parseInt(null == m1.get("zdjczfjh")?"0":m1.get("zdjczfjh"));
            array[18] += Integer.parseInt(null == m1.get("zdjssh")?"0":m1.get("zdjssh"));
            array[19] += Integer.parseInt(null == m1.get("zdsfsjjczzjh")?"0": m1.get("zdsfsjjczzjh"));
            array[20] += Integer.parseInt(null == m1.get("galsgk")?"0":m1.get("galsgk"));
            array[21] += Integer.parseInt(null == m1.get("ybbj")?"0":m1.get("ybbj"));
            array[22] += Integer.parseInt(null == m1.get("ybjczzjjsjh")?"0":m1.get("ybjczzjjsjh"));
            array[23] += Integer.parseInt(null == m1.get("ryzf")?"0":m1.get("ryzf"));
            array[24] += Integer.parseInt(null == m1.get("azzs")?"0":m1.get("azzs"));
            //省基地数，任何机构总计的时候不应该累加
            array[25] = Integer.parseInt(null == m1.get("sqyjds")?"0":m1.get("sqyjds"));
            array[26] += Integer.parseInt(null == m1.get("sqyazry")?"0":m1.get("sqyazry"));
            //地市基地数，当单位是省厅的时候，地市基地进行累加，其他情况就展示查询到的数据
            if(Constants.OrgLevel.LEVEL_SFT.equals(level)) {
                array[27]  += Integer.parseInt(null == m1.get("dsqyjds")?"0":m1.get("dsqyjds"));
            }else {
                dsqyjdsCount = Math.max(dsqyjdsCount,Integer.parseInt(null == m1.get("dsqyjds")?"0":m1.get("dsqyjds")));
                array[27]  = dsqyjdsCount;
            }
            array[28] += Integer.parseInt(null == m1.get("dsqyazry")?"0":m1.get("dsqyazry"));
            //区县基地数同理
            boolean b = Constants.OrgLevel.LEVEL_SFT.equals(level) || Constants.OrgLevel.LEVEL_DSSFJ.equals(level);
            if(b) {
                array[29] += Integer.parseInt(null == m1.get("qxqyjds")?"0":m1.get("qxqyjds"));
            }else {
                qxqyjdsCount = Math.max(qxqyjdsCount,Integer.parseInt(null == m1.get("qxqyjds")?"0":m1.get("qxqyjds")));
                array[29] = qxqyjdsCount;
            }
            array[30] += Integer.parseInt(null == m1.get("qxqyazry")?"0":m1.get("qxqyazry"));
            if(Constants.OrgLevel.LEVEL_SFT.equals(level) ||
                    Constants.OrgLevel.LEVEL_DSSFJ.equals(level) ||
                    Constants.OrgLevel.LEVEL_QXSFJ.equals(level)) {
                array[31] += Integer.parseInt(null == m1.get("jdqyjds")?"0":m1.get("jdqyjds"));
            }else {
                jdqyjdsCount =  Math.max(jdqyjdsCount,Integer.parseInt(null == m1.get("jdqyjds")?"0":m1.get("jdqyjds")));
                array[31] = jdqyjdsCount;
            }
            array[32] += Integer.parseInt(null == m1.get("jdqyazry")?"0":m1.get("jdqyazry"));
            array[33] += Integer.parseInt(null == m1.get("azjdlsjmszc")?"0":m1.get("azjdlsjmszc"));
            array[34] = Integer.parseInt(null == m1.get("szfjds")?"0":m1.get("szfjds"));
            array[35] += Integer.parseInt(null == m1.get("szfazrs")?"0":m1.get("szfazrs"));
            if(Constants.OrgLevel.LEVEL_SFT.equals(level)) {
                array[36] += Integer.parseInt(null == m1.get("dszfjds")?"0":m1.get("dszfjds"));
            }else {
                dszfjdsCount = Math.max(dszfjdsCount,Integer.parseInt(null == m1.get("dszfjds")?"0":m1.get("dszfjds")));
                array[36] = dszfjdsCount;
            }
            array[37] += Integer.parseInt(null == m1.get("dszfazrs")?"0":m1.get("dszfazrs"));
            if(b) {
                array[38] += Integer.parseInt(null == m1.get("qxzfjds")?"0":m1.get("qxzfjds"));
            }else {
                qxzfjdsCount = Math.max(qxzfjdsCount,Integer.parseInt(null == m1.get("qxzfjds")?"0":m1.get("qxzfjds")));
                array[38] = qxzfjdsCount;
            }
            array[39] += Integer.parseInt(null == m1.get("qxzfazrs")?"0":m1.get("qxzfazrs"));
            array[40] += Integer.parseInt(null == m1.get("azzrt")?"0":m1.get("azzrt"));
            array[41] += Integer.parseInt(null == m1.get("azgxygw")?"0":m1.get("azgxygw"));
            array[42] += Integer.parseInt(null == m1.get("zzcyrs")?"0":m1.get("zzcyrs"));
            array[43] += Integer.parseInt(null == m1.get("zzcylsjmszc")?"0":m1.get("zzcylsjmszc"));
            array[44] += Integer.parseInt(null == m1.get("gtjyrs")?"0":m1.get("gtjyrs"));
            array[45] += Integer.parseInt(null == m1.get("gtjylsjmszc")?"0":m1.get("gtjylsjmszc"));
            array[46] += Integer.parseInt(null == m1.get("qyxnrs")?"0":m1.get("qyxnrs"));
            array[47] += Integer.parseInt(null == m1.get("qyxnlsjmszc")?"0":m1.get("qyxnlsjmszc"));
            array[48] += Integer.parseInt(null == m1.get("qtazfs")?"0":m1.get("qtazfs"));
            array[49] += Integer.parseInt(null == m1.get("sydj")?"0":m1.get("sydj"));
            array[50] += Integer.parseInt(null == m1.get("jnpx")?"0":m1.get("jnpx"));
            array[51] += Integer.parseInt(null == m1.get("jytj")?"0":m1.get("jytj"));
            array[52] += Integer.parseInt(null == m1.get("lszdshbz")?"0":m1.get("lszdshbz"));
            array[53] += Integer.parseInt(null == m1.get("lstkrygy")?"0":m1.get("lstkrygy"));
            array[54] += Integer.parseInt(null == m1.get("lsyljz")?"0":m1.get("lsyljz"));
            array[55] += Integer.parseInt(null == m1.get("lsjyjz")?"0":m1.get("lsjyjz"));
            array[56] += Integer.parseInt(null == m1.get("lszfjz")?"0":m1.get("lszfjz"));
            array[57] += Integer.parseInt(null == m1.get("lslsjz")?"0":m1.get("lslsjz"));
            array[58] += Integer.parseInt(null == m1.get("bjzs")?"0":m1.get("bjzs"));
            array[59] += Integer.parseInt(null == m1.get("rdrt")?"0":m1.get("rdrt"));
            array[60] += Integer.parseInt(null == m1.get("drldzw")?"0":m1.get("drldzw"));
            array[61] += Integer.parseInt(null == m1.get("sdzjgbz")?"0":m1.get("sdzjgbz"));
            array[62] += Integer.parseInt(null == m1.get("cxfz")?"0":m1.get("cxfz"));
            array[63] += Integer.parseInt(null == m1.get("jyxmsf")?"0":m1.get("jyxmsf"));
            array[64] += Integer.parseInt(null == m1.get("kssxmsf")?"0":m1.get("kssxmsf"));
            array[65] += Integer.parseInt(null == m1.get("jcsqjz")?"0":m1.get("jcsqjz"));
            array[66] += Integer.parseInt(null == m1.get("cxfma")?"0":m1.get("cxfma"));
            array[67] += Integer.parseInt(null == m1.get("slrs")?"0":m1.get("slrs"));
        }
        //子级(c)机构数
        map.put("cjgs",array[0]);
        //子级(c)机构人数
        map.put("cjgrs",array[1]);
        //子级的子级(cc)机构数
        map.put("ccjgs",array[2]);
        //子级的子级机构人数
        map.put("ccjgrs",array[3]);
        //子级的子级的子级机构数
        map.put("cccjgs",array[4]);
        //子级的子级的子级机构人数
        map.put("cccjgrs",array[5]);
        //从事安帮的社会工作者-社工人数
        map.put("sgrs",array[6]);
        //从事安帮的社会志愿者-志愿者人数
        map.put("zyzrs",array[7]);
        //衔接人员总数-衔接总数
        map.put("xjzs",array[8]);
        //监狱刑满释放人员-监狱释放
        map.put("jysf",array[9]);
        //看守所刑满释放人员-看守所释放
        map.put("ksssf",array[10]);
        //解除社区矫正人员-社区矫正转入
        map.put("sqjzzr",array[11]);
        //男性
        map.put("man",array[12]);
        //女性
        map.put("woman",array[13]);
        //农村籍人员-农村籍
        map.put("ncj",array[14]);
        //三无人员-三无
        map.put("sanwu",array[15]);
        //重点帮教对象-重点帮教
        map.put("zdbj",array[16]);
        //基层政府接回-重点基层政府接回
        map.put("zdjczfjh",array[17]);
        //监所送回原籍-重点监所送回
        map.put("zdjssh",array[18]);
        //司法所及基层组织接回-重点司法所及基层组织接回
        map.put("zdsfsjjczzjh",array[19]);
        //公安机关落实管控措施-公安落实管控
        map.put("galsgk",array[20]);
        //一般帮教对象-一般帮教
        map.put("ybbj",array[21]);
        //基层组织及家属接回-一般基层组织及家属接回
        map.put("ybjczzjjsjh",array[22]);
        //人员自返
        map.put("ryzf",array[23]);
        //安置总人数-安置总数
        map.put("azzs",array[24]);
        //省企业基地数
        map.put("sqyjds",array[25]);
        //省企业安置人员
        map.put("sqyazry",array[26]);
        //地市企业基地数
        map.put("dsqyjds",array[27]);
        //地市企业安置人员
        map.put("dsqyazry",array[28]);
        //区县企业基地数
        map.put("qxqyjds",array[29]);
        //区县企业安置人员
        map.put("qxqyazry",array[30]);
        //街道企业基地数
        map.put("jdqyjds",array[31]);
        //街道企业安置人员
        map.put("jdqyazry",array[32]);
        //落实减免税政策-安置基地落实减免税政策
        map.put("azjdlsjmszc",array[33]);
        //省政府基地数
        map.put("szfjds",array[34]);
        //省政府安置人员
        map.put("szfazrs",array[35]);
        //地市政府基地数
        map.put("dszfjds",array[36]);
        //地市政府安置人员
        map.put("dszfazrs",array[37]);
        //区县政府基地数
        map.put("qxzfjds",array[38]);
        //区县政府安置人员
        map.put("qxzfazrs",array[39]);
        //落实责任田-安置责任田
        map.put("azzrt",array[40]);
        //公益性岗位安置-安置公益性岗位
        map.put("azgxygw",array[41]);
        //自主创业人数
        map.put("zzcyrs",array[42]);
        //自主创业落实减免税政策
        map.put("zzcylsjmszc",array[43]);
        //个体经营人数
        map.put("gtjyrs",array[44]);
        //个体经营落实减免税政策
        map.put("gtjylsjmszc",array[45]);
        //企业吸纳人数
        map.put("qyxnrs",array[46]);
        //企业吸纳落实减免税
        map.put("qyxnlsjmszc",array[47]);
        //其他安置方式
        map.put("qtazfs",array[48]);
        //失业登记
        map.put("sydj",array[49]);
        //技能培训
        map.put("jnpx",array[50]);
        //推荐就业
        map.put("jytj",array[51]);
        //落实最低生活保障
        map.put("lszdshbz",array[52]);
        //落实特困人员供养
        map.put("lstkrygy",array[53]);
        //落实医疗救助
        map.put("lsyljz",array[54]);
        //落实教育救助
        map.put("lsjyjz",array[55]);
        //落实住房救助
        map.put("lszfjz",array[56]);
        //落实临时救助
        map.put("lslsjz",array[57]);
        //帮教总数
        map.put("bjzs",array[58]);
        //入党入团
        map.put("rdrt",array[59]);
        //担任领导职务
        map.put("drldzw",array[60]);
        //受党政机关表彰
        map.put("sdzjgbz",array[61]);
        //安置帮教人员五年内重新犯罪-重新犯罪
        map.put("cxfz",array[62]);
        //监狱刑满释放
        map.put("jyxmsf",array[63]);
        //看守所刑满释放
        map.put("kssxmsf",array[64]);
        //解除社区矫正
        map.put("jcsqjz",array[65]);
        //重新犯命案
        map.put("cxfma",array[66]);
        //失联人员
        map.put("slrs",array[67]);
    }

    /**
     * 描述
     * @param map map
     * @return String
     */
    private static String comparingByName(Map<String,String> map) {
        return null == map.get("childsId")?map.get("codeId"):map.get("childsId");
    }

    private void getListJyInfo(Map<String,Integer> map,List<Integer> statisticalReports) {
        //死刑缓期
        map.put("xq1",statisticalReports.get(0));
        map.put("xq2",statisticalReports.get(1));
        map.put("xq3",statisticalReports.get(2));
        //刑期3- 10
        map.put("xq4",statisticalReports.get(3));
        //3年以下
        map.put("xq5",statisticalReports.get(4));
        map.put("gz1",statisticalReports.get(5));
        map.put("gz2",statisticalReports.get(6));
        map.put("gz3",statisticalReports.get(7));
        map.put("gz4",statisticalReports.get(8));
        map.put("gz5",statisticalReports.get(9));
        map.put("rztd1",statisticalReports.get(10));
        map.put("rztd2",statisticalReports.get(11));
        map.put("rztd3",statisticalReports.get(12));
        //重点帮教人员
        map.put("wxpg1",statisticalReports.get(13));
        //一般帮教对象
        map.put("wxpg2",statisticalReports.get(14));
        //三无人员
        map.put("wxpg3",statisticalReports.get(15));
        //再犯罪人数
        map.put("wxpg4",statisticalReports.get(16));
        //核查状态;1:待核查,2:核查中,3:核查成功,4:核查失败
        map.put("hczt1",statisticalReports.get(17));
        map.put("hczt2",statisticalReports.get(18));
        map.put("hczt3",statisticalReports.get(19));
        map.put("hczt4",statisticalReports.get(20));
        //        1:衔接成功2：衔接中3：衔接失败4：未衔接5：待衔接
        map.put("xjzt1",statisticalReports.get(21));
        map.put("xjzt2",statisticalReports.get(22));
        map.put("xjzt3",statisticalReports.get(23));
        map.put("xjzt4",statisticalReports.get(24));
        map.put("xjzt5",statisticalReports.get(25));
        // 特赦人员
        map.put("wxpg5",statisticalReports.get(26));
        // 三假人员
        map.put("wxpg6",statisticalReports.get(27));
    }

    /**
     * 八大指标比较顺序
     */
    static class MapKeyComparator implements Comparator<String> {

        @Override
        public int compare(String str1,String str2) {
            if(str1.startsWith("all0")) {
                str1 = str1.replace("all0","");
            } else {
                str1 = str1.replace("all","");
            }
            if(str2.startsWith("all0")) {
                str2 = str2.replace("all0","");
            } else {
                str2 = str2.replace("all","");
            }
            return Integer.valueOf(str1).compareTo(Integer.valueOf(str2));
        }
    }
    ////////////////////////////////8、首页地图统计////////////////////////////////



    /**
     * 获取地图未展示新区统计项数据
     * @param code 区划编码
     * @return 统计项和对应的人数
     */
    @Override
    public List<HashMap<String,Object>> getWzsAzbj(String code) {
        return allCensusMapper.getWzsAzbj(code);
    }

    /**
     * 获取地图未展示新区统计项数据
     * @param code 区划编码
     * @return 统计项和对应的人数
     */
    @Override
    public List<HashMap<String,Object>> getWzsZdbj(String code) {
        return allCensusMapper.getWzsZdbj(code);
    }

    /**
     * 获取地图未展示新区统计项数据
     * @param code 区划编码
     * @return 统计项和对应的人数
     */
    @Override
    public List<HashMap<String,Object>> getWzsWxj(String code) {
        return allCensusMapper.getWzsWxj(code);
    }

    /**
     * 获取地图未展示新区统计项数据
     * @param code 区划编码
     * @return 统计项和对应的人数
     */
    @Override
    public List<HashMap<String,Object>> getWzsSl(String code) {
        return allCensusMapper.getWzsSl(code);
    }
    /**
     * 数据统计分析 - 数据分析预警 - 数据分析预警 - 获取超标预警数据
     * @param departid departid
     * @param level level 当前登陆用户level
     * @return Map<String,Object>
     */
    @Override
    public Map<String,Object> getMap(String departid,String level) {
        DecimalFormat df = new DecimalFormat("0.00");
        Map<String,Object> map = new LinkedHashMap<>(16);
        //1、核查-核查成功人数（state为3的且approval不为1的数据）
        Integer[] cgRenShu = {0};
        CompletableFuture<Void> cgRenShuTask = CompletableFuture.runAsync(() -> {
            long startTime = System.currentTimeMillis();
            cgRenShu[0] = allCensusMapper.hccgRenShu(departid);
            long endTime = System.currentTimeMillis();
            map.put("cgRenShu",cgRenShu[0]);
            log.info("异步查询----->核查成功人数:{}",cgRenShu[0]);
            log.info("异步查询----->核查成功人数耗时:{}",endTime-startTime);
        });
        //2、核查-核查总数(核查成功+核查失败+核查中)
        Integer[] zongRenShu = {0};
        CompletableFuture<Void> zongRenShuTask = CompletableFuture.runAsync(() -> {
            long startTime = System.currentTimeMillis();
            zongRenShu[0] = allCensusMapper.zongRenShu(departid,Integer.parseInt(level));
            long endTime = System.currentTimeMillis();
            map.put("zongRenShu",zongRenShu[0]);
            log.info("异步查询----->核查总数:{}",zongRenShu[0]);
            log.info("异步查询----->核查总数耗时:{}",endTime-startTime);
        });
        //4、衔接 - 衔接成功人数
        Integer[] xianJieCgRenShu = {0};
        CompletableFuture<Void> xianJieCgRenShuTask = CompletableFuture.runAsync(() -> {
            long startTime = System.currentTimeMillis();
            xianJieCgRenShu[0] = allCensusMapper.getXianJieCgRenShu(departid);
            long endTime = System.currentTimeMillis();
            map.put("xianJieCGRenShu",xianJieCgRenShu[0]);
            log.info("异步查询----->衔接成功人数:{}",xianJieCgRenShu[0]);
            log.info("异步查询----->衔接成功人数耗时:{}",endTime-startTime);
        });
        //5、衔接 - 衔接总数：衔接成功+衔接失败+衔接中
        Integer[] xianJieZongShu = {0};
        CompletableFuture<Void> xianJieZongShuTask = CompletableFuture.runAsync(() -> {
            long startTime = System.currentTimeMillis();
            xianJieZongShu[0] = allCensusMapper.getXianJieZongShu(departid);
            long endTime = System.currentTimeMillis();
            map.put("xianJieZongShu",xianJieZongShu[0]);
            log.info("异步查询----->衔接总数:{}",xianJieZongShu[0]);
            log.info("异步查询----->衔接总数耗时:{}",endTime-startTime);
        });
        //7、已安置人数
        Integer[] yiAnZhiRenShu = {0};
        CompletableFuture<Void> yiAnZhiRenShuTask = CompletableFuture.runAsync(() -> {
            long startTime = System.currentTimeMillis();
            yiAnZhiRenShu[0] = allCensusMapper.getYiAnZhiRenShu(departid);
            long endTime = System.currentTimeMillis();
            log.info("异步查询----->已安置人数:{}",yiAnZhiRenShu[0]);
            log.info("异步查询----->已安置人数耗时:{}",endTime-startTime);
        });
        //8、进入安置帮教人数
        Integer[] anZhiZongShu = {0};
        CompletableFuture<Void> anZhiZongShuTask = CompletableFuture.runAsync(() -> {
            anZhiZongShu[0] = allCensusMapper.getAnZhiZongShu(departid);
            log.info("异步查询----->进入安置帮教人数:{}",anZhiZongShu[0]);
        });
        //9、未安置人数
        CompletableFuture<Void> weiZanZhiRenShuTask = CompletableFuture.runAsync(() -> {
            long startTime = System.currentTimeMillis();
            Map<String,Object> stringObjectMap = AssemblyConversionUtils.transferAssembly(level);
            Integer weiZanZhiRenShu = allCensusMapper.getWeiAnZhi(departid,level,stringObjectMap);
            long endTime = System.currentTimeMillis();
            map.put("weiZanZhiRenShu",weiZanZhiRenShu);
            log.info("异步查询----->未安置人数:{}",weiZanZhiRenShu);
            log.info("异步查询----->未安置人数耗时:{}",endTime-startTime);
        });
        //10、帮教人数(有救助或者有帮教的人数)
        Integer[] bangJiaoRenShu = {0};
        CompletableFuture<Void> bangJiaoRenShuTask = CompletableFuture.runAsync(() -> {
            long startTime = System.currentTimeMillis();
            bangJiaoRenShu[0] = allCensusMapper.getBangJiaoRenShu(departid,level);
            long endTime = System.currentTimeMillis();
            log.info("异步查询----->帮教人数:{}",bangJiaoRenShu[0]);
            log.info("异步查询----->帮教人数耗时:{}",endTime-startTime);
        });
        //11、失联人数
        CompletableFuture<Void> shiLianRenShuTask = CompletableFuture.runAsync(() -> {
            long startTime = System.currentTimeMillis();
            Map<String,Object> stringObjectMap = AssemblyConversionUtils.transferAssembly(level);
            Integer shiLianRenShu = allCensusMapper.getShiLian(departid,level,stringObjectMap);
            long endTime = System.currentTimeMillis();
            map.put("shiLianRenShu",shiLianRenShu);
            log.info("异步查询----->失联人数:{}",shiLianRenShu);
            log.info("异步查询----->失联人数耗时:{}",endTime-startTime);
        });
        //12、高风险人数
        CompletableFuture<Void> gaoFengXianTask = CompletableFuture.runAsync(() -> {
            long startTime = System.currentTimeMillis();
            Map<String,Object> stringObjectMap = AssemblyConversionUtils.transferAssembly(level);
            Integer gaoFengXian = allCensusMapper.getWeiXian(departid,level,stringObjectMap);
            long endTime = System.currentTimeMillis();
            map.put("gaoFengXian",gaoFengXian);
            log.info("异步查询----->高风险人数:{}",gaoFengXian);
            log.info("异步查询----->高风险人数耗时:{}",endTime-startTime);
        });
        //13、重新犯罪人数
        Integer[] zaiFanZuiRen = {0};
        CompletableFuture<Void> zaiFanZuiRenTask = CompletableFuture.runAsync(() -> {
            long startTime = System.currentTimeMillis();
            Map<String,Object> stringObjectMap = AssemblyConversionUtils.transferAssembly(level);
            zaiFanZuiRen[0] = allCensusMapper.getZaiFanZui(departid,level,stringObjectMap);
            long endTime = System.currentTimeMillis();
            map.put("zaiFanZuiRen",zaiFanZuiRen[0]);
            log.info("异步查询----->重新犯罪人数:{}",zaiFanZuiRen[0]);
            log.info("异步查询----->重新犯罪人数耗时:{}",endTime-startTime);
        });
        //14、解除安帮总人数
        Integer[] jcAnBangZongShu = {0};
        CompletableFuture<Void> jcAnBangZongShuTask = CompletableFuture.runAsync(() -> {
            long startTime = System.currentTimeMillis();
            Map<String,Object> stringObjectMap = AssemblyConversionUtils.transferAssembly(level);
            jcAnBangZongShu[0] = allCensusMapper.getJcAnBangZongShu(departid,level,stringObjectMap);
            long endTime = System.currentTimeMillis();
            log.info("异步查询----->解除安帮总人数:{}",jcAnBangZongShu[0]);
            log.info("异步查询----->解除安帮总人数耗时:{}",endTime-startTime);
        });
        //阻塞上面全部异步线程执行完毕
        CompletableFuture<Void> allTasks = CompletableFuture.allOf(cgRenShuTask,zongRenShuTask,xianJieCgRenShuTask,xianJieZongShuTask,yiAnZhiRenShuTask,anZhiZongShuTask,weiZanZhiRenShuTask,bangJiaoRenShuTask,shiLianRenShuTask,gaoFengXianTask,zaiFanZuiRenTask,jcAnBangZongShuTask);
        allTasks.join();
        log.info(">>>>>>>>>开始计算各种比例<<<<<<<<<<");
        //3、核查成功率：核查率(核查率=核查成功+核查失败/核查成功+核查失败+核查中) 2020-09-09修改为核查成功率：计算规则-->核查成功/核查总数
        if(0 != zongRenShu[0]) {
            float num = (float)cgRenShu[0] / zongRenShu[0];
            String hechalv = df.format(num * 100);
            map.put("hechalv",hechalv + "%");
        } else {
            map.put("hechalv","0.00");
        }
        //2、衔接成功率(衔接率=衔接成功+衔接失败/衔接成功+衔接失败+衔接中) 2020-09-09修改为衔接成功率：计算规则-->衔接成功/衔接总数
        if(0 != xianJieZongShu[0]) {
            float xjnum = (float)xianJieCgRenShu[0] / xianJieZongShu[0];
            String xianjielv = df.format(xjnum * 100);
            map.put("xianjielv",xianjielv + "%");
        } else {
            map.put("xianjielv","0.00");
        }
        //3、安置率
        if(0 != anZhiZongShu[0]) {
            float anznum = (float)yiAnZhiRenShu[0] / anZhiZongShu[0];
            String anzhilv = df.format(anznum * 100);
            map.put("anzhilv",anzhilv + "%");
        } else {
            map.put("anzhilv","0.00");
        }
        //4、帮教率（有救助或者有帮教的人数）/ 帮教对象总人数（全部人员列表=安置总人数=帮教总人数）
        if(0 != anZhiZongShu[0]) {
            float bjnum = (float)bangJiaoRenShu[0] / anZhiZongShu[0];
            String bjlv = df.format(bjnum * 100);
            map.put("bjlv",bjlv + "%");
        } else {
            map.put("bjlv","0.00");
        }
        //5、重新犯罪率
        if(0 != jcAnBangZongShu[0]) {
            float zfznum = (float)zaiFanZuiRen[0] / jcAnBangZongShu[0];
            String zfzlv = df.format(zfznum * 100);
            map.put("zfzlv",zfzlv + "%");
        } else {
            map.put("zfzlv","0.00");
        }
        return map;
    }

    /**
     * 数据统计分析 - 数据分析预警 - 数据分析预警 - 趋势预警：未来第一月、未来第二月、未来第三月。预释放人员趋势预警：未来第一月、未来第二月、未来第三月。
     * @param departid departid
     * @return Map<String,Object>
     */
    @Override
    public Map<String,Object> getQuShi(String departid) {
        //预释放人员趋势预警
        List<String>[] yuShiFangList = new List[1];
        CompletableFuture<Void> yuShiFangListTask = CompletableFuture.runAsync(() -> {
            yuShiFangList[0] = allCensusMapper.getYuShiFang(departid);
            log.info("异步查询----->预释放人员:{}",yuShiFangList[0]);
        });
        //重点人员衔接趋势预警
        List<String>[] zhongDianRenYuanlist = new List[1];
        CompletableFuture<Void> zdrslistTask = CompletableFuture.runAsync(() -> {
            zhongDianRenYuanlist[0] = allCensusMapper.getZhongDianRenYuan(departid);
            log.info("异步查询----->重点人员:{}",zhongDianRenYuanlist[0]);
        });
        CompletableFuture<Void> allTasks = CompletableFuture.allOf(yuShiFangListTask,zdrslistTask);
        allTasks.join();
        Map<String,Object> map = new LinkedHashMap<>(16);
        //预释放人员近三个月
        map.put("yuShiFangList",yuShiFangList[0]);
        //重点人员近三个月
        map.put("zhongDianRenYuanlist",zhongDianRenYuanlist[0]);
        return map;
    }

    /**
     * 数据统计分析 - 数据分析预警 - 数据分析预警 - "核查成功率","衔接成功率","安置率","帮教率","重新犯罪人数"
     * @param departid departid
     * @param level level
     * @param type type
     * @return Result
     */
    @Override
    public Result queryEchartsData(String departid,String level,int type) {
        Date date = new Date();
        //获取当前年份
        String dateStr = new SimpleDateFormat("yyyy").format(date);
        //获取当前月份
        AtomicInteger month = new AtomicInteger(date.getMonth() + 1);
        //获取去年的年数
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.YEAR,-1);
        //定义一个空数组用来存放视图对象
        List<BigDecimal> vo = Collections.synchronizedList(new ArrayList<>(16));
        //获取去年的年份
        String oldYear = new SimpleDateFormat("yyyy").format(calendar.getTime());
        //定义一个步长
        int i = 1;
        //初始下一年的月份为1
        AtomicInteger newMon = new AtomicInteger(1);
        //定义一个返回的月份视图
        List<String> timer = Collections.synchronizedList(new ArrayList<>(16));
        //如果总人数为空数据库返回的结果是null，准备替换null的变量
        BigDecimal zore = new BigDecimal("0.00");
        //获取12月的数据
        CompletableFuture[] zdrslistTask = new CompletableFuture[12];
        while(Constants.Number.NUM_TWELVE >= i) {
            //定义从去年这个月到今年这个月的月数
            String str;
            //如果是12月，说明应该进到下一年
            if(Constants.Number.NUM_TWELVE == month.get()) {
                //获取月份
                str = 10 > newMon.get() ? dateStr + "-0" + newMon : dateStr + "-" + newMon;
                //月份需要自增
                newMon.addAndGet(1);
            } else {
                //计算去年这个月到12个月的月份 比如今年10月，会获取到11,12月份的数据
                int mon = Constants.Number.NUM_TWELVE - (Constants.Number.NUM_TWELVE - month.get()) + Constants.Number.NUM_ONE;
                //获取月份字符串
                str = Constants.Number.NUM_TEN > mon ? oldYear + "-0" + mon : oldYear + "-" + mon;
                //月份需要自增
                month.addAndGet(1);
            }
            int finalI = i;
            i++;
            //异步执行查询
            zdrslistTask[finalI - 1] = CompletableFuture.runAsync(() -> {
                log.info(">>>>>{}<<<<<开始执行第{}次任务",type,finalI);
                BigDecimal val;
                if(1 == type) {
                    //核查成功率：main表中的state=3,核查表中的approve字段不为1 / 核查表的总数  时间是main表中的connection字段
                    long start = System.currentTimeMillis();
                    val = allCensusMapper.getEchartsHcData(str,level,departid);
                    long end = System.currentTimeMillis();
                    log.info("核查成功率:耗时{}",start-end);
                } else if(2 == type) {
                    //衔接成功率=本月衔接成功人数/本月衔接成功人数+本月衔接失败人数(时间根据衔接表中的edittime)
                    val = allCensusMapper.getEchartsXjData(str,departid);
                } else if(3 == type) {
                    //安置率=本月安置人数/本月安置人数+本月转到安置帮教人数(安置人数的时间是根据安置表中的安置时间，转到安置帮教的时间是安帮表的创建时间)
                    val = allCensusMapper.getEchartsAzData(str,departid);
                } else if(4 == type) {
                    //帮教率=本月帮教人数/本月帮教人数+本月转到安置帮教人数(帮教人数的时间是根据帮教中的帮教时间，转到安置帮教的时间是安帮表的创建时间)
                    val = allCensusMapper.getEchartsBjData(str,departid);
                } else if(5 == type) {
                    //重新犯罪人数：安帮人员解除安帮表中解除状态为重新犯罪的人数
                    Map<String,Object> stringObjectMap = AssemblyConversionUtils.transferAssembly(level);
                    val = allCensusMapper.getEchartsCxfzData(str,departid,Integer.parseInt(level),stringObjectMap);
                } else {
                    val = new BigDecimal("0.00");
                }
                if(1 != finalI) {
                    CompletableFuture<Void> preTask = CompletableFuture.allOf(zdrslistTask[finalI - 2]);
                    preTask.join();
                }
                //判断null，并且格式bigdecimal小数位2位
                if(5 == type) {
                    vo.add(val);
                } else {
                    vo.add(null == val ? zore : val.setScale(2,RoundingMode.HALF_UP).multiply(new BigDecimal(100)));
                }
                //添加返回的月份视图
                timer.add(finalI - 1,str);
            });
        }
        CompletableFuture<Void> allTasks = CompletableFuture.allOf(zdrslistTask);
        allTasks.join();
        log.info(">>>>>>>>>>>任务执行完毕，组装返回结果<<<<<<<<<<");
        //返回的map视图对象
        Map<String,Object> map = new HashMap<>(16);
        map.put("columns",timer);
        map.put("rows",vo);
        return Result.success(map);
    }

    /**
     * 数据统计分析 - 数据分析预警 - 数据分析预警 - 数据统计："高风险人数"
     * @param departid departid
     * @param level level
     * @param type type
     * @return Result
     */
    @Override
    public Result queryGaoFengXianData(String departid,String level,int type) {
        //定义一个返回的月份视图
        List<String> coldatas = Collections.synchronizedList(new ArrayList<>(16));
        //如果总人数为空数据库返回的结果是null，准备替换null的变量
        List<Integer> rowdatas = Collections.synchronizedList(new ArrayList<>(16));
        //获取当前的年份
        Date date = new Date();
        //获取当前年份
        String dateStr = new SimpleDateFormat("yyyy").format(date);
        //循环五次
        CompletableFuture[] zdrslistTask = new CompletableFuture[6];
        for(int i = Constants.Number.NUM_FIVE; 0 <= i; i--) {
            int finalI = i;
            zdrslistTask[i] = CompletableFuture.runAsync(() -> {
                String year = String.valueOf(Integer.parseInt(dateStr) - finalI);
                Map<String,Object> stringObjectMap = AssemblyConversionUtils.transferAssembly(level);
                Integer tempVar = allCensusMapper.getEchartsGfxData(year,departid,Integer.parseInt(level),stringObjectMap);
                if(5 != finalI) {
                    CompletableFuture<Void> preTask = CompletableFuture.allOf(zdrslistTask[finalI + 1]);
                    preTask.join();
                }
                coldatas.add(year);
                rowdatas.add(tempVar);
                log.info("异步查询----->{}年，高风险人数:{}",year,tempVar);
            });
        }
        CompletableFuture<Void> allTasks = CompletableFuture.allOf(zdrslistTask);
        allTasks.join();
        //返回的map视图对象
        Map<String,Object> map = new HashMap<>(16);
        map.put("columns",coldatas);
        map.put("rows",rowdatas);
        return Result.success(map);
    }
    ////////////////////////////////2、工作排名////////////////////////////////

    /**
     * 数据统计分析 - 工作排名 - 工作排名 - （核查成功率）
     * @param user user
     * @return Object
     */
    @Override
    public Object checkList(UserDTO user) {
        JobRanking jobRanking = new JobRanking();
        String level = user.getLevel();
        String departid = user.getDepartid();
        String orgid = user.getOrgid();
        if(null != level) {
            //司法厅
            if(StringUtils.equals(level,Constants.OrgLevel.LEVEL_SFT)) {
                //直辖市处理
                if(Constants.XzqhCode.BEIJING.equals(departid)) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.BEIJING_SXQ);
                    return allCensusMapper.checkList2(jobRanking);
                } else if(Constants.XzqhCode.TIANJIN.equals(departid)) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.TIANJIN_SXQ);
                    return allCensusMapper.checkList2(jobRanking);
                } else if(Constants.XzqhCode.CHONGQING.equals(departid)) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.CHONGQING_SXQ);
                    return allCensusMapper.checkList2(jobRanking);
                } else if(Constants.XzqhCode.SHANGHAI.equals(departid)) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.SHANGHAI_SXQ);
                    return allCensusMapper.checkList2(jobRanking);
                } else {
                    //地市排名
                    jobRanking.setNativepro(departid);
                    List<JobRanking> jobRankingList = allCensusMapper.checkList(jobRanking);
                    return filterList(jobRankingList);
                }
            }
            //地级市司法局  地市可以看到本市区县的排名。
            if(StringUtils.equals(level,Constants.OrgLevel.LEVEL_DSSFJ)) {
                jobRanking.setNativecity(departid);
                if(Constants.XzqhCode.BEIJING.equals(jobRanking.getNativecity())) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.BEIJING_SXQ);
                }
                if(Constants.XzqhCode.TIANJIN.equals(jobRanking.getNativecity())) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.TIANJIN_SXQ);
                }
                if(Constants.XzqhCode.CHONGQING.equals(jobRanking.getNativecity())) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.CHONGQING_SXQ);
                }
                if(Constants.XzqhCode.SHANGHAI.equals(jobRanking.getNativecity())) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.SHANGHAI_SXQ);
                }
                List<JobRanking> jobRankingList = allCensusMapper.checkList2(jobRanking);
                return this.filterList(jobRankingList);
            }
            //区县司法局 区县司法局显示本区县司法所的排名
            if(StringUtils.equals(level,Constants.OrgLevel.LEVEL_QXSFJ)) {
                jobRanking.setNativecou(departid);
                return allCensusMapper.checkList3(jobRanking);
            } else if(StringUtils.equals(level,Constants.OrgLevel.LEVEL_SFS)) {
                //司法所   司法所只显示自己在本区县的排名
                jobRanking.setNativecou(orgid);
                jobRanking.setNativevill(departid);
                return allCensusMapper.checkList4(jobRanking);
            } else if(StringUtils.equals(level,Constants.OrgLevel.LEVEL_JYJ)) {
                // 监狱局管理员角色
                jobRanking.setPrisonFather(departid);
                return allCensusMapper.checkList7(jobRanking);
            } else if(StringUtils.equals(level,Constants.OrgLevel.LEVEL_JY)) {
                // 监狱用户分类 监狱用户 ziji
                jobRanking.setPrisonFather(orgid);
                jobRanking.setPrison(departid);
                return allCensusMapper.checkList8(jobRanking);
            }
        }
        return null;
    }

    /**
     * 数据统计分析 - 工作排名 - 工作排名 - （衔接成功率）
     * @param user user
     * @return Object
     */
    @Override
    public Object returnReceipt(UserDTO user) {
        JobRanking jobRanking = new JobRanking();
        String level = user.getLevel();
        String departid = user.getDepartid();
        String orgid = user.getOrgid();
        if(null != level) {
            //省司法厅
            if(StringUtils.equals(level,Constants.OrgLevel.LEVEL_SFT)) {
                //直辖市处理
                if(Constants.XzqhCode.BEIJING.equals(departid)) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.BEIJING_SXQ);
                    return allCensusMapper.returnReceipt2(jobRanking);
                } else if(Constants.XzqhCode.TIANJIN.equals(departid)) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.TIANJIN_SXQ);
                    return allCensusMapper.returnReceipt2(jobRanking);
                } else if(Constants.XzqhCode.CHONGQING.equals(departid)) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.CHONGQING_SXQ);
                    return allCensusMapper.returnReceipt2(jobRanking);
                } else if(Constants.XzqhCode.SHANGHAI.equals(departid)) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.SHANGHAI_SXQ);
                    return allCensusMapper.returnReceipt2(jobRanking);
                } else {
                    jobRanking.setNativepro(departid);
                    List<JobRanking> rankingList = allCensusMapper.returnReceipt(jobRanking);
                    return filterList(rankingList);
                }
            }
            //地级市司法局  地市可以看到本市区县的排名。
            if(StringUtils.equals(level,Constants.OrgLevel.LEVEL_DSSFJ)) {
                jobRanking.setNativecity(departid);
                if(Constants.XzqhCode.BEIJING.equals(jobRanking.getNativecity())) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.BEIJING_SXQ);
                }
                if(Constants.XzqhCode.TIANJIN.equals(jobRanking.getNativecity())) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.TIANJIN_SXQ);
                }
                if(Constants.XzqhCode.CHONGQING.equals(jobRanking.getNativecity())) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.CHONGQING_SXQ);
                }
                if(Constants.XzqhCode.SHANGHAI.equals(jobRanking.getNativecity())) {
                    jobRanking.setNativecity(Constants.ZxsSxqCode.SHANGHAI_SXQ);
                }
                return allCensusMapper.returnReceipt2(jobRanking);
            }
            //区县司法局 区县司法局显示本区县司法所的排名
            if(StringUtils.equals(level,Constants.OrgLevel.LEVEL_QXSFJ)) {
                jobRanking.setNativecou(departid);
                return allCensusMapper.returnReceipt3(jobRanking);
            } else if(StringUtils.equals(level,Constants.OrgLevel.LEVEL_SFS)) {
                //司法所   司法所只显示自己在本区县的排名
                jobRanking.setNativecou(orgid);
                jobRanking.setNativevill(departid);
                return allCensusMapper.returnReceipt4(jobRanking);
            } else if(StringUtils.equals(level,Constants.OrgLevel.LEVEL_JYJ)) {
                // 监狱局管理员角色
                jobRanking.setPrisonFather(departid);
                return allCensusMapper.returnReceipt7(jobRanking);
            } else if(StringUtils.equals(level,Constants.OrgLevel.LEVEL_JY)) {
                // 监狱用户分类 监狱用户 ziji
                jobRanking.setPrisonFather(orgid);
                jobRanking.setPrison(departid);
                return allCensusMapper.returnReceipt8(jobRanking);
            }
        }
        return null;
    }

    /**
     * 数据统计分析 - 工作排名 - 工作排名 - 过滤掉那些户籍地址名称为空的数据
     * @param rankingList rankingList
     * @return List<JobRanking>
     */
    private List<JobRanking> filterList(List<JobRanking> rankingList) {
        if(!CollectionUtils.isEmpty(rankingList)) {
            return rankingList.stream().filter(ranking -> !StringUtils.isEmpty(ranking.getName()))
                              .collect(Collectors.toList());
        }
        return rankingList;
    }
    ////////////////////////////////3、报告生成////////////////////////////////

    /**
     * 查询报告名称
     * @param ttype ttype
     * @return List<Map < String,Object>>
     */
    @Override
    public List<Map<String,Object>> getbgTemplateList(String ttype) {
        return allCensusMapper.getbgTemplateList(ttype);
    }

    /**
     * 查询报告路径信息
     * @param id id
     * @return List<Map < String,Object>>
     */
    @Override
    public List<Map<String,Object>> getbgTemplateInfoById(String id) {
        return allCensusMapper.getbgTemplateInfoById(id);
    }

    /**
     * 查询模板数据
     * @param map map
     * @return ConcurrentHashMap<String,Integer>
     */
    @Override
    public ConcurrentHashMap<String,Integer> getAllList(Map<String,Object> map) {
        ConcurrentHashMap<String,Integer> counts = new ConcurrentHashMap<>(16);
        CompletableFuture<Void> azbjZrsTask = CompletableFuture.runAsync(() -> {
            //1、安置帮教总人数
            Integer azbjZrs = allCensusMapper.getAzbjZrs(map);
            counts.put("azbjZrs",null != azbjZrs ? azbjZrs : 0);
            log.info("异步查询----->安置帮教总人数:{}",azbjZrs);
        });
        CompletableFuture<Void> zzgzryTask = CompletableFuture.runAsync(() -> {
            //2、专职工作人员
            Integer zzgzry = allCensusMapper.getZzgzry(map);
            counts.put("zzgzry",null != zzgzry ? zzgzry : 0);
            log.info("异步查询----->专职工作人员:{}",zzgzry);
        });
        CompletableFuture<Void> shgzzTask = CompletableFuture.runAsync(() -> {
            //3、从事安置帮教工作的社会工作者
            Integer shgzz = allCensusMapper.getShgzz(map);
            counts.put("shgzz",null != shgzz ? shgzz : 0);
            log.info("异步查询----->从事安置帮教工作的社会工作者:{}",shgzz);
        });
        CompletableFuture<Void> shzyzTask = CompletableFuture.runAsync(() -> {
            //4、社会志愿者
            Integer shzyz = allCensusMapper.getShzyz(map);
            counts.put("shzyz",null != shzyz ? shzyz : 0);
            log.info("异步查询----->社会志愿者:{}",shzyz);
        });
        CompletableFuture<Void> hcfxryTask = CompletableFuture.runAsync(() -> {
            //5、应核查服刑人员信息
            Integer hcfxry = allCensusMapper.getHcfxry(map);
            counts.put("hcfxry",null != hcfxry ? hcfxry : 0);
            log.info("异步查询----->应核查服刑人员信息:{}",hcfxry);
        });
        CompletableFuture<Void> sjHcTask = CompletableFuture.runAsync(() -> {
            //6、实际核查
            Integer sjHc = allCensusMapper.getSjHc(map);
            counts.put("sjHc",null != sjHc ? sjHc : 0);
            log.info("异步查询----->实际核查:{}",sjHc);
        });
        CompletableFuture<Void> hccgTask = CompletableFuture.runAsync(() -> {
            //8、核查成功
            Integer hccg = allCensusMapper.getHccg(map);
            counts.put("hccg",null != hccg ? hccg : 0);
            log.info("异步查询----->核查成功:{}",hccg);
        });
        CompletableFuture<Void> hcsbTask = CompletableFuture.runAsync(() -> {
            //9、核查失败
            Integer hcsb = allCensusMapper.getHcsb(map);
            counts.put("hcsb",null != hcsb ? hcsb : 0);
            log.info("异步查询----->核查失败:{}",hcsb);
        });
        CompletableFuture<Void> dhcTask = CompletableFuture.runAsync(() -> {
            //10、等待核实
            Integer dhc = allCensusMapper.getDhc(map);
            counts.put("dhc",null != dhc ? dhc : 0);
            log.info("异步查询----->等待核实:{}",dhc);
        });
        CompletableFuture<Void> xjxsryTask = CompletableFuture.runAsync(() -> {
            //11、共衔接刑释解矫人员
            Integer xjxsry = allCensusMapper.getXjxsry(map);
            counts.put("xjxsry",null != xjxsry ? xjxsry : 0);
            log.info("异步查询----->共衔接刑释解矫人员:{}",xjxsry);
        });
        CompletableFuture<Void> jyxmsfTask = CompletableFuture.runAsync(() -> {
            //12、监狱刑满释放
            Integer jyxmsf = allCensusMapper.getJyxmsf(map);
            counts.put("jyxmsf",null != jyxmsf ? jyxmsf : 0);
            log.info("异步查询----->监狱刑满释放:{}",jyxmsf);
        });
        CompletableFuture<Void> kssxmsfTask = CompletableFuture.runAsync(() -> {
            //13、看守所刑满释放
            Integer kssxmsf = allCensusMapper.getKssxmsf(map);
            counts.put("kssxmsf",null != kssxmsf ? kssxmsf : 0);
            log.info("异步查询----->看守所刑满释放:{}",kssxmsf);
        });
        CompletableFuture<Void> sqjzTask = CompletableFuture.runAsync(() -> {
            //14、社区矫正期满转入安置帮教
            Integer sqjz = allCensusMapper.getSqjz(map);
            counts.put("sqjz",null != sqjz ? sqjz : 0);
            log.info("异步查询----->社区矫正期满转入安置帮教:{}",sqjz);
        });
        CompletableFuture<Void> qnazryTask = CompletableFuture.runAsync(() -> {
            //15、安置刑满释放人员
            Integer qnazry = allCensusMapper.getQnazry(map);
            counts.put("qnazry",null != qnazry ? qnazry : 0);
            log.info("异步查询----->安置刑满释放人员:{}",qnazry);
        });
        CompletableFuture<Void> lszrtTask = CompletableFuture.runAsync(() -> {
            //17、落实责任田
            Integer lszrt = allCensusMapper.getLszrt(map);
            counts.put("lszrt",null != lszrt ? lszrt : 0);
            log.info("异步查询----->落实责任田:{}",lszrt);
        });
        CompletableFuture<Void> gyxgwazTask = CompletableFuture.runAsync(() -> {
            //18、公益性岗位安置
            Integer gyxgwaz = allCensusMapper.getGyxgwaz(map);
            counts.put("gyxgwaz",null != gyxgwaz ? gyxgwaz : 0);
            log.info("异步查询----->公益性岗位安置:{}",gyxgwaz);
        });
        CompletableFuture<Void> zzcyTask = CompletableFuture.runAsync(() -> {
            //19、自主创业
            Integer zzcy = allCensusMapper.getZzcy(map);
            counts.put("zzcy",null != zzcy ? zzcy : 0);
            log.info("异步查询----->自主创业:{}",zzcy);
        });
        CompletableFuture<Void> csgtjyTask = CompletableFuture.runAsync(() -> {
            //20、从事个体经营
            Integer csgtjy = allCensusMapper.getCsgtjy(map);
            counts.put("csgtjy",null != csgtjy ? csgtjy : 0);
            log.info("异步查询----->从事个体经营:{}",csgtjy);
        });
        CompletableFuture<Void> qyjjTask = CompletableFuture.runAsync(() -> {
            //21、企业和经济实体吸纳就业
            Integer qyjj = allCensusMapper.getQyjj(map);
            counts.put("qyjj",null != qyjj ? qyjj : 0);
            log.info("异步查询----->企业和经济实体吸纳就业:{}",qyjj);
        });
        CompletableFuture<Void> qtazTask = CompletableFuture.runAsync(() -> {
            //22、其他方式安置就业
            Integer qtaz = allCensusMapper.getQtaz(map);
            counts.put("qtaz",null != qtaz ? qtaz : 0);
            log.info("异步查询----->其他方式安置就业:{}",qtaz);
        });
        CompletableFuture<Void> qngbjTask = CompletableFuture.runAsync(() -> {
            //23、全年共帮教
            Integer qngbj = allCensusMapper.getQngbj(map);
            counts.put("qngbj",null != qngbj ? qngbj : 0);
            log.info("异步查询----->全年共帮教:{}",qngbj);
        });
        CompletableFuture<Void> lszdbzTask = CompletableFuture.runAsync(() -> {
            //24、落实最低生活保障
            Integer lszdbz = allCensusMapper.getLszdbz(map);
            counts.put("lszdbz",null != lszdbz ? lszdbz : 0);
            log.info("异步查询----->落实最低生活保障:{}",lszdbz);
        });
        CompletableFuture<Void> lstkTask = CompletableFuture.runAsync(() -> {
            //25、落实特困人员供养
            Integer lstk = allCensusMapper.getLstk(map);
            counts.put("lstk",null != lstk ? lstk : 0);
            log.info("异步查询----->落实特困人员供养:{}",lstk);
        });
        CompletableFuture<Void> lsyljzTask = CompletableFuture.runAsync(() -> {
            //26、落实医疗救助
            Integer lsyljz = allCensusMapper.getLsyljz(map);
            counts.put("lsyljz",null != lsyljz ? lsyljz : 0);
            log.info("异步查询----->落实医疗救助:{}",lsyljz);
        });
        CompletableFuture<Void> lsjyjzTask = CompletableFuture.runAsync(() -> {
            //27、落实教育救助
            Integer lsjyjz = allCensusMapper.getLsjyjz(map);
            counts.put("lsjyjz",null != lsjyjz ? lsjyjz : 0);
            log.info("异步查询----->落实教育救助:{}",lsjyjz);
        });
        CompletableFuture<Void> lszfjzTask = CompletableFuture.runAsync(() -> {
            //28、落实住房救助
            Integer lszfjz = allCensusMapper.getLszfjz(map);
            counts.put("lszfjz",null != lszfjz ? lszfjz : 0);
            log.info("异步查询----->落实住房救助:{}",lszfjz);
        });
        CompletableFuture<Void> sydjTask = CompletableFuture.runAsync(() -> {
            //29、失业登记
            Integer sydj = allCensusMapper.getSydj(map);
            counts.put("sydj",null != sydj ? sydj : 0);
            log.info("异步查询----->失业登记:{}",sydj);
        });
        CompletableFuture<Void> jnpxTask = CompletableFuture.runAsync(() -> {
            //30、技能培训
            Integer jnpx = allCensusMapper.getJnpx(map);
            counts.put("jnpx",null != jnpx ? jnpx : 0);
            log.info("异步查询----->技能培训:{}",jnpx);
        });
        CompletableFuture<Void> tjjyTask = CompletableFuture.runAsync(() -> {
            //31、推荐就业
            Integer tjjy = allCensusMapper.getTjjy(map);
            counts.put("tjjy",null != tjjy ? tjjy : 0);
            log.info("异步查询----->推荐就业:{}",tjjy);
        });
        CompletableFuture<Void> jcazbjTask = CompletableFuture.runAsync(() -> {
            //32、全年共解除安置帮教
            Integer jcazbj = allCensusMapper.getJcazbj(map);
            counts.put("jcazbj",null != jcazbj ? jcazbj : 0);
            log.info("异步查询----->解除安置帮教:{}",jcazbj);
        });
        CompletableFuture<Void> cxfzTask = CompletableFuture.runAsync(() -> {
            //33、重新犯罪
            Integer cxfz = allCensusMapper.getCxfz(map);
            counts.put("cxfz",null != cxfz ? cxfz : 0);
            log.info("异步查询----->重新犯罪:{}",cxfz);
        });
        CompletableFuture<Void> xjzsTask = CompletableFuture.runAsync(() -> {
            //34、衔接总数
            Integer xjzs = allCensusMapper.getXjzs(map);
            counts.put("xjzs",null != xjzs ? xjzs : 0);
            log.info("异步查询----->衔接总数:{}",xjzs);
        });
        CompletableFuture<Void> bjTask = CompletableFuture.runAsync(() -> {
            //35、帮教总数
            Integer bj = allCensusMapper.getbjzs(map);
            counts.put("bj",null != bj ? bj : 0);
            log.info("异步查询----->帮教总数:{}",bj);
        });
        CompletableFuture<Void> childTasks = CompletableFuture.allOf(azbjZrsTask,zzgzryTask,shgzzTask,shzyzTask,hcfxryTask,sjHcTask,hccgTask,hcsbTask,dhcTask,xjxsryTask,jyxmsfTask,kssxmsfTask,sqjzTask,qnazryTask,lszrtTask,gyxgwazTask,zzcyTask,csgtjyTask,qyjjTask,qtazTask,qngbjTask,lszdbzTask,lstkTask,lsyljzTask,lsjyjzTask,lszfjzTask,sydjTask,jnpxTask,tjjyTask,jcazbjTask,cxfzTask,xjzsTask,bjTask);
        childTasks.join();
        Integer hcfxry = counts.get("hcfxry");
        Integer sjHc = counts.get("sjHc");
        Integer qnazry = counts.get("qnazry");
        Integer xjxsry = counts.get("xjxsry");
        //核查率
        if(Constants.Number.NUM_ZERO.equals(hcfxry)) {
            counts.put("hcl",0);
        }else {
            counts.put("hcl",sjHc*100 / hcfxry);
        }
        if(Constants.Number.NUM_ZERO.equals(xjxsry)) {
            counts.put("azlYxj",0);
        }else {
            counts.put("azlYxj",qnazry*100/xjxsry);
        }
        return counts;
    }
    /**
     * 近5年刑满释放人员安置率  近5年刑满释放人员帮教率
     * @param list list
     * @return Map<String,HashMap < String,String>>
     */
    @Override
    public Map<String,HashMap<String,String>> serviceForAzAndBj(List<Map<String,Object>> list) {
        Map<String,HashMap<String,String>> resultMaps = new HashMap<>(2);
        int size = list.size();
        CompletableFuture[] cLists = new CompletableFuture[size];
        HashMap<String,String> azlmap = new HashMap<>(16);
        HashMap<String,String> bjlmap = new HashMap<>(16);
        for(int i = 0; i < size; i++) {
            int finalI = i;
            int nianfen = (int)list.get(finalI).get("year");
            cLists[i] = CompletableFuture.runAsync(() -> {
                String s = String.valueOf(nianfen - finalI);
                Integer[] azzs = new Integer[1];
                CompletableFuture<Void> azzsTask = CompletableFuture.runAsync(() -> {
                    azzs[0] = allCensusMapper.getAzzs(list.get(finalI));
                    log.info("异步查询{}年----->查询安置总数:{}",s,azzs[0]);
                });
                Integer[] bjz = new Integer[1];
                CompletableFuture<Void> bjzTask = CompletableFuture.runAsync(() -> {
                    bjz[0] = allCensusMapper.getbjzs(list.get(finalI));
                    log.info("异步查询{}年----->查询帮教总数:{}",s,bjz[0]);
                });
                Integer[] bfjzzs = new Integer[1];
                CompletableFuture<Void> bfjzzsTask = CompletableFuture.runAsync(() -> {
                    bfjzzs[0] = allCensusMapper.getBfJzzs(list.get(finalI));
                    log.info("异步查询{}年----->查询帮扶救助总数:{}",s,bfjzzs[0]);
                });
                CompletableFuture<Void> childTasks = CompletableFuture.allOf(azzsTask,bjzTask,bfjzzsTask);
                childTasks.join();
                //安置率为安置总数/帮教总数
                Integer azl = 0;
                if(null != bjz[0] && 0 != bjz[0]) {
                    azl = (int)((azzs[0] * 1.0 / bjz[0]) * 100);
                }
                azlmap.put(s + "年",String.valueOf(azl));
                //帮教率为帮扶救助总数/帮教总数
                Integer bjl5 = 0;
                if(null != bjz[0] && 0 != bjz[0]) {
                    bjl5 = (int)((bfjzzs[0] * 1.0 / bjz[0]) * 100);
                }
                bjlmap.put(s + "年",String.valueOf(bjl5));
            });
        }
        CompletableFuture<Void> allTasks = CompletableFuture.allOf(cLists);
        allTasks.join();
        resultMaps.put("azlmap",azlmap);
        resultMaps.put("bjlmap",bjlmap);
        return resultMaps;
    }
    /**
     * 待核查人数 / 核查失败- 首页上方
     * @param departId departId
     * @param level level
     * @param type type
     * @return Integer
     */
    @Override
    public Integer getCountOfJs(String departId,String level,String type) {
        return allCensusMapper.getCountOfJs(departId,level,type);
    }

    /**
     * 首页统计 - 点击首页通知栏数据改变状态 - 全部帮教对象数量
     * @param contentId contentId
     * @param type type
     * @param account account
     * @return Integer
     */
    @Override
    public Integer changeState(String contentId,String type,String account) {
        Integer count = allCensusMapper.getCount(contentId,type,account);
        if(0 == count) {
            ViewState viewState = new ViewState();
            viewState.setContentId(contentId);
            viewState.setType(type);
            viewState.setCreateuser(account);
            viewState.setState(Constants.NumberStr.NUM_STR_ONE);
            if(!viewState.insertOrUpdate()) {
                return 0;
            }
        }
        return 1;
    }

    /**
     * 全部帮教对象数量
     * @param departId 部门id
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> allAzbjCount(String departId) {
        return allCensusMapper.allAzbjCount(departId);
    }

    //首页缓存统计
    /**
     * 司法厅---帮教对象人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> sftbjdxrs() {
        return allCensusMapper.sftbjdxrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 地市司法局---帮教对象人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> dssfjbjdxrs() {
        return allCensusMapper.dssfjbjdxrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 区县司法局---帮教对象人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> qxsfjbjdxrs() {
        return allCensusMapper.qxsfjbjdxrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 司法厅---重点帮教对象数量
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> sftzdbjdxrs() {
        return allCensusMapper.sftzdbjdxrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 司法厅---重点帮教对象数量
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> dssfjzdbjdxrs() {
        return allCensusMapper.dssfjzdbjdxrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 司法厅---重点帮教对象数量
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> qxsfjzdbjdxrs() {
        return allCensusMapper.qxsfjzdbjdxrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 司法厅--未衔接人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> sftwxjrs() {
        return allCensusMapper.sftwxjrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 地市司法局--未衔接人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> dssfjwxjrs() {
        return allCensusMapper.dssfjwxjrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 区县司法局--未衔接人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> qxsfjwxjrs() {
        return allCensusMapper.qxsfjwxjrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 街道--未衔接人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> jdwxjrs() {
        return allCensusMapper.jdwxjrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 司法厅---失联人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> sftslrs() {
        return allCensusMapper.sftslrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 地市司法局---失联人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> dssfjslrs() {
        return allCensusMapper.dssfjslrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 区县司法局---失联人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> qxsfjslrs() {
        return allCensusMapper.qxsfjslrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 街道---失联人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> slrs() {
        return allCensusMapper.slrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 监狱 待衔接重点帮教对象人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> dxjzddxrs() {
        return allCensusMapper.dxjzddxrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 监狱 待衔接人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> dxjrs() {
        return allCensusMapper.dxjrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 监狱 未衔接人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> jywxjrs() {
        return allCensusMapper.jywxjrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 监狱 核查失败人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> hcsbrs() {
        return allCensusMapper.hcsbrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 监狱 未进行出监、危险性评估人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> wpgrs() {
        return allCensusMapper.wpgrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 监狱 待核查人数
     * @return List<AzbjRsVo>
     */
    @Override
    public List<AzbjRsVo> dhcrs() {
        return allCensusMapper.dhcrs(CodeUrlUtils.getLocalCodeStartTwo());
    }

    /**
     * 社矫 核查失败人员
     * @return List<AzbjRsVo>
     */
    @Override
    public AzbjRsVo sjhcsbrs(String departId) {
        return allCensusMapper.sjhcsbrs(departId);
    }
    /**
     * 社矫 核查成功人员
     * @return List<AzbjRsVo>
     */
    @Override
    public AzbjRsVo sjhccgrs(String departId) {
        return allCensusMapper.sjhccgrs(departId);
    }
    /**
     * 社矫 衔接中人数
     * @return List<AzbjRsVo>
     */
    @Override
    public AzbjRsVo sjxjzrs(String departId) {
        return allCensusMapper.sjxjzrs(departId);
    }
    /**
     * 社矫 衔接成功人员
     * @return List<AzbjRsVo>
     */
    @Override
    public AzbjRsVo sjxjcgrs(String departId) {
        return allCensusMapper.sjxjcgrs(departId);
    }
    /**
     * 社矫 衔接失败人员
     * @return List<AzbjRsVo>
     */
    @Override
    public AzbjRsVo sjxjsbrs(String departId) {
        return allCensusMapper.sjxjsbrs(departId);
    }
    /**
     * 社矫 未衔接人员
     * @return List<AzbjRsVo>
     */
    @Override
    public AzbjRsVo sjwxjrs(String departId) {
        return allCensusMapper.sjwxjrs(departId);
    }

    /**
     * 获取azbj_rs表中字段数量
     * @return 表中字段数量
     */
    @Override
    public Integer getFieldCount(String field) {
        return allCensusMapper.getFieldCount(field);
    }

    /**
     * 目前再系统管理-运维功能中新增登录统计功能
     * @param departid 部门id
     * @param yearMonth 年月
     * @return String
     */
    @Override
    public String loginCensus(String departid,String yearMonth) {
        //处理第一次点击默认日期未当年当月
        int year;
        int month;
        if(StringUtils.equals(yearMonth,Constants.NumberStr.NUM_STR_FU_ONE)) {
            Calendar date = Calendar.getInstance();
            year = date.get(Calendar.YEAR);
            month = date.get(Calendar.MONTH)+1;
            yearMonth = year+"-"+month;
        }else {
            String[] split = yearMonth.split("-");
            year = Integer.parseInt(split[0]);
            month = Integer.parseInt(split[1]);
        }
        //直辖市特殊处理
        if(StrUtil.containsEquals(departid,Constants.XzqhCode.BEIJING,Constants.XzqhCode.TIANJIN,Constants.XzqhCode.SHANGHAI,Constants.XzqhCode.CHONGQING)) {
            List<Map<String,String>> list = systemCodeMapper.selectChilds(departid);
            departid = list.get(0).get("departId");
        }
        //获取当前部门的子级单位
        List<Map<String,String>> childs = systemCodeMapper.selectChilds(departid);
        List<Map<String,String>> result = new ArrayList<>(16);
        //todo:需要判断childs是否为空
        //获取当前部门子级单位的所有子孙级
        int i=1;
        for(Map<String,String> map : childs) {
            Map<String,String> temp = new HashMap<>(16);
            //cid是当前部门所有子级单位的id
            String cId = map.get("departId");
            //cName是当前部门所有子级单位的name
            String cName = map.get("departName");
            Integer childsCount = systemCodeMapper.selectAllChilds(cId);
            Integer workDay = WorkDayUtil.getDate(year,month);
            Integer loginCount = allCensusMapper.loginCensus(cId,yearMonth);
            //todo:登录率计算:本级及下级地区总登录次数/(本级及下级地区数*工作日数)
            temp.put("id",i+"");
            temp.put("area",cName);
            temp.put("childs",childsCount + "");
            temp.put("workDay",workDay + "");
            temp.put("loginCount",loginCount + "");
            temp.put("login","100%");
            i++;
            result.add(temp);
        }
        return JsonUtil.toText1(result);
    }
}